mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-13 04:25:00 -05:00
wrapped-key-ring: use UncachedKeyRing in ImportKeysListLoader
This commit is contained in:
parent
10ad7be46b
commit
91a8a6c2d1
@ -20,18 +20,16 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.content.AsyncTaskLoader;
|
import android.support.v4.content.AsyncTaskLoader;
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPKeyRing;
|
|
||||||
import org.spongycastle.openpgp.PGPObjectFactory;
|
|
||||||
import org.spongycastle.openpgp.PGPUtil;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
|
import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ImportKeysListLoader
|
public class ImportKeysListLoader
|
||||||
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
@ -116,7 +114,6 @@ public class ImportKeysListLoader
|
|||||||
private void generateListOfKeyrings(InputData inputData) {
|
private void generateListOfKeyrings(InputData inputData) {
|
||||||
|
|
||||||
boolean isEmpty = true;
|
boolean isEmpty = true;
|
||||||
int nonPgpCounter = 0;
|
|
||||||
|
|
||||||
PositionAwareInputStream progressIn = new PositionAwareInputStream(
|
PositionAwareInputStream progressIn = new PositionAwareInputStream(
|
||||||
inputData.getInputStream());
|
inputData.getInputStream());
|
||||||
@ -129,28 +126,16 @@ public class ImportKeysListLoader
|
|||||||
|
|
||||||
// read all available blocks... (asc files can contain many blocks with BEGIN END)
|
// read all available blocks... (asc files can contain many blocks with BEGIN END)
|
||||||
while (bufferedInput.available() > 0) {
|
while (bufferedInput.available() > 0) {
|
||||||
isEmpty = false;
|
// todo deal with non-keyring objects?
|
||||||
InputStream in = PGPUtil.getDecoderStream(bufferedInput);
|
List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
|
||||||
PGPObjectFactory objectFactory = new PGPObjectFactory(in);
|
for(UncachedKeyRing key : rings) {
|
||||||
|
addToData(key);
|
||||||
// go through all objects in this block
|
isEmpty = false;
|
||||||
Object obj;
|
|
||||||
while ((obj = objectFactory.nextObject()) != null) {
|
|
||||||
Log.d(Constants.TAG, "Found class: " + obj.getClass());
|
|
||||||
|
|
||||||
if (obj instanceof PGPKeyRing) {
|
|
||||||
PGPKeyRing newKeyring = (PGPKeyRing) obj;
|
|
||||||
addToData(newKeyring);
|
|
||||||
} else {
|
|
||||||
Log.e(Constants.TAG, "Object not recognized as PGPKeyRing!");
|
|
||||||
nonPgpCounter++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(Constants.TAG, "Exception on parsing key file!", e);
|
Log.e(Constants.TAG, "Exception on parsing key file!", e);
|
||||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
|
||||||
nonPgpCounter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
@ -158,14 +143,9 @@ public class ImportKeysListLoader
|
|||||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
||||||
(mData, new FileHasNoContent());
|
(mData, new FileHasNoContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonPgpCounter > 0) {
|
|
||||||
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
|
||||||
(mData, new NonPgpPart(nonPgpCounter));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToData(PGPKeyRing keyring) {
|
private void addToData(UncachedKeyRing keyring) {
|
||||||
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), keyring);
|
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), keyring);
|
||||||
mData.add(item);
|
mData.add(item);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user