diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-03-11 00:11:27 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-03-11 00:11:27 +0100 |
commit | 74f8ec0365385d61990290b4922dc05d92a4a439 (patch) | |
tree | 813f7fdff8a8ba1f09fd1513efd0f97bca23d6a5 /OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider | |
parent | 535f2caf2c7dc815a622cfd9ff67fa59214b5da2 (diff) | |
download | open-keychain-74f8ec0365385d61990290b4922dc05d92a4a439.tar.gz open-keychain-74f8ec0365385d61990290b4922dc05d92a4a439.tar.bz2 open-keychain-74f8ec0365385d61990290b4922dc05d92a4a439.zip |
certs: close in from both sides :)
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider')
-rw-r--r-- | OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index b6bfc372a..4d1fc7d81 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -20,6 +20,8 @@ package org.sufficientlysecure.keychain.provider; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.Date; import org.spongycastle.bcpg.ArmoredOutputStream; @@ -59,25 +61,30 @@ public class ProviderHelper { /** * Private helper method to get PGPKeyRing from database */ - public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) { + public static Map<Long, PGPKeyRing> getPGPKeyRings(Context context, Uri queryUri) { Cursor cursor = context.getContentResolver().query(queryUri, - new String[]{KeyRings._ID, KeyRings.KEY_RING_DATA}, null, null, null); + new String[]{KeyRings._ID, KeyRings.MASTER_KEY_ID, KeyRings.KEY_RING_DATA}, null, null, null); - PGPKeyRing keyRing = null; - if (cursor != null && cursor.moveToFirst()) { + Map<Long, PGPKeyRing> result = new HashMap<Long, PGPKeyRing>(cursor.getCount()); + if (cursor != null && cursor.moveToFirst()) do { int keyRingDataCol = cursor.getColumnIndex(KeyRings.KEY_RING_DATA); + int masterKeyIdCol = cursor.getColumnIndex(KeyRings.MASTER_KEY_ID); byte[] data = cursor.getBlob(keyRingDataCol); if (data != null) { - keyRing = PgpConversionHelper.BytesToPGPKeyRing(data); + result.put(cursor.getLong(masterKeyIdCol), PgpConversionHelper.BytesToPGPKeyRing(data)); } - } + + } while(cursor.moveToNext()); if (cursor != null) { cursor.close(); } - return keyRing; + return result; + } + public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) { + return getPGPKeyRings(context, queryUri).values().iterator().next(); } /** @@ -322,6 +329,30 @@ public class ProviderHelper { } /** + * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing + */ + private static ContentProviderOperation buildPublicCertOperations(Context context, + long keyRingRowId, + int rank, + long keyId, + PGPSignature cert, + boolean verified) + throws IOException { + ContentValues values = new ContentValues(); + values.put(Certs.KEY_RING_ROW_ID, keyRingRowId); + values.put(Certs.RANK, rank); + values.put(Certs.KEY_ID, keyId); + values.put(Certs.KEY_ID_CERTIFIER, cert.getKeyID()); + values.put(Certs.CREATION, cert.getCreationTime().getTime() / 1000); + values.put(Certs.VERIFIED, verified); + values.put(Certs.KEY_DATA, cert.getEncoded()); + + Uri uri = Certs.buildCertsUri(Long.toString(keyRingRowId)); + + return ContentProviderOperation.newInsert(uri).withValues(values).build(); + } + + /** * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing */ private static ContentProviderOperation buildPublicUserIdOperations(Context context, |