mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
use longsparsearrays instead of hashmaps in that one place
This commit is contained in:
parent
956b9a12bb
commit
79117b1ef8
@ -26,6 +26,7 @@ import android.database.Cursor;
|
|||||||
import android.database.DatabaseUtils;
|
import android.database.DatabaseUtils;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.support.v4.util.LongSparseArray;
|
||||||
|
|
||||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.spongycastle.bcpg.S2K;
|
import org.spongycastle.bcpg.S2K;
|
||||||
@ -167,33 +168,35 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, PGPKeyRing> getPGPKeyRings(Uri queryUri) {
|
public LongSparseArray<PGPKeyRing> getPGPKeyRings(Uri queryUri) {
|
||||||
Cursor cursor = mContentResolver.query(queryUri,
|
Cursor cursor = mContentResolver.query(queryUri,
|
||||||
new String[]{KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA},
|
new String[]{KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA},
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
Map<Long, PGPKeyRing> result = new HashMap<Long, PGPKeyRing>(cursor.getCount());
|
LongSparseArray<PGPKeyRing> result = new LongSparseArray<PGPKeyRing>(cursor.getCount());
|
||||||
if (cursor != null && cursor.moveToFirst()) do {
|
try {
|
||||||
long masterKeyId = cursor.getLong(0);
|
if (cursor != null && cursor.moveToFirst()) do {
|
||||||
byte[] data = cursor.getBlob(1);
|
long masterKeyId = cursor.getLong(0);
|
||||||
if (data != null) {
|
byte[] data = cursor.getBlob(1);
|
||||||
result.put(masterKeyId, PgpConversionHelper.BytesToPGPKeyRing(data));
|
if (data != null) {
|
||||||
|
result.put(masterKeyId, PgpConversionHelper.BytesToPGPKeyRing(data));
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
|
||||||
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PGPKeyRing getPGPKeyRing(Uri queryUri) throws NotFoundException {
|
public PGPKeyRing getPGPKeyRing(Uri queryUri) throws NotFoundException {
|
||||||
Map<Long, PGPKeyRing> result = getPGPKeyRings(queryUri);
|
LongSparseArray<PGPKeyRing> result = getPGPKeyRings(queryUri);
|
||||||
if (result.isEmpty()) {
|
if (result.size() == 0) {
|
||||||
throw new NotFoundException("PGPKeyRing object not found!");
|
throw new NotFoundException("PGPKeyRing object not found!");
|
||||||
} else {
|
} else {
|
||||||
return result.values().iterator().next();
|
return result.valueAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +270,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get a list of owned secret keys, for verification filtering
|
// get a list of owned secret keys, for verification filtering
|
||||||
Map<Long, PGPKeyRing> allKeyRings = getPGPKeyRings(KeyRingData.buildSecretKeyRingUri());
|
LongSparseArray<PGPKeyRing> allKeyRings = getPGPKeyRings(KeyRingData.buildSecretKeyRingUri());
|
||||||
// special case: available secret keys verify themselves!
|
// special case: available secret keys verify themselves!
|
||||||
if (secretRing != null)
|
if (secretRing != null)
|
||||||
allKeyRings.put(secretRing.getSecretKey().getKeyID(), secretRing);
|
allKeyRings.put(secretRing.getSecretKey().getKeyID(), secretRing);
|
||||||
@ -305,7 +308,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// verify signatures from known private keys
|
// verify signatures from known private keys
|
||||||
if (allKeyRings.containsKey(certId)) {
|
if (allKeyRings.indexOfKey(certId) >= 0) {
|
||||||
// mark them as verified
|
// mark them as verified
|
||||||
cert.init(new JcaPGPContentVerifierBuilderProvider().setProvider(
|
cert.init(new JcaPGPContentVerifierBuilderProvider().setProvider(
|
||||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME),
|
Constants.BOUNCY_CASTLE_PROVIDER_NAME),
|
||||||
|
Loading…
Reference in New Issue
Block a user