aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-07-31 17:11:06 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-07-31 17:11:06 +0200
commit9475285013accafd24d5bc14da9ba01ca218cbe8 (patch)
tree2a55a2750e67986306be86261db174eb6142d003 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
parent1d2c93ca8ae4c75e92b5da74e262b9476f22f172 (diff)
downloadopen-keychain-9475285013accafd24d5bc14da9ba01ca218cbe8.tar.gz
open-keychain-9475285013accafd24d5bc14da9ba01ca218cbe8.tar.bz2
open-keychain-9475285013accafd24d5bc14da9ba01ca218cbe8.zip
Better exception handling for import of keys
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java48
1 files changed, 14 insertions, 34 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
index 4a8eb0cb1..9996e0381 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
@@ -37,7 +37,7 @@ import java.util.List;
public class ImportKeysListLoader
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
- public static class FileHasNoContentException extends Exception {
+ public static class NoValidKeysException extends Exception {
}
public static class NonPgpPartException extends Exception {
@@ -118,8 +118,6 @@ public class ImportKeysListLoader
* @return
*/
private void generateListOfKeyrings(InputData inputData) {
- boolean isEmpty = true;
-
PositionAwareInputStream progressIn = new PositionAwareInputStream(
inputData.getInputStream());
@@ -127,42 +125,24 @@ public class ImportKeysListLoader
// PGPObject chunks after the first one, e.g. files with several consecutive ASCII
// armor blocks
BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
- bufferedInput.mark(1024);
try {
-
- // read all available blocks... (asc files can contain many blocks with BEGIN END)
- while (bufferedInput.available() > 0) {
- // TODO: deal with non-keyring objects?
- List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
- for (UncachedKeyRing key : rings) {
- ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
- mData.add(item);
- mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
- isEmpty = false;
- }
+ // parse all keyrings
+ List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
+ for (UncachedKeyRing key : rings) {
+ ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
+ mData.add(item);
+ mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
}
- } catch (Exception e) {
- Log.e(Constants.TAG, "Exception on parsing key file!", e);
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "IOException on parsing key file! Return NoValidKeysException!", e);
- try {
- bufferedInput.reset();
- } catch (IOException e1) {
- }
- Log.d(Constants.TAG, "Last 1024 byte input data: " + convertStreamToString(bufferedInput));
- mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
- }
-
- if (isEmpty) {
- FileHasNoContentException e = new FileHasNoContentException();
- Log.e(Constants.TAG, "File has no content!", e);
+ NoValidKeysException e1 = new NoValidKeysException();
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
- (mData, e);
+ (mData, e1);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "Other Exception on parsing key file!", e);
+ mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
}
}
- static String convertStreamToString(java.io.InputStream is) {
- java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
- return s.hasNext() ? s.next() : "";
- }
-
}