diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-10-09 00:58:07 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-10-09 00:58:07 +0200 |
commit | 49b4ff63122988dc1587844e6b4b2ee5d0855385 (patch) | |
tree | 5935990ff98baa2ee0f224ff666fad433e2f451a /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java | |
parent | 3165f3ffa8b16dcee11e6dfc21492b556d0c1de3 (diff) | |
download | open-keychain-49b4ff63122988dc1587844e6b4b2ee5d0855385.tar.gz open-keychain-49b4ff63122988dc1587844e6b4b2ee5d0855385.tar.bz2 open-keychain-49b4ff63122988dc1587844e6b4b2ee5d0855385.zip |
Replace PgpGeneralException with NotFoundException where appropriate
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java | 146 |
1 files changed, 55 insertions, 91 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index 5a3770f2d..7be8cdd3b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -30,21 +30,21 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.util.Log; -/** This implementation of KeyRing provides a cached view of PublicKeyRing +/** + * This implementation of KeyRing provides a cached view of PublicKeyRing * objects based on database queries exclusively. - * + * <p/> * This class should be used where only few points of data but no actual * cryptographic operations are required about a PublicKeyRing which is already * in the database. This happens commonly in UI code, where parsing of a PGP * key for examination would be a very expensive operation. - * + * <p/> * Each getter method is implemented using a more or less expensive database * query, while object construction is (almost) free. A common pattern is * mProviderHelper.getCachedKeyRing(uri).getterMethod() - * + * <p/> * TODO Ensure that the values returned here always match the ones returned by * the parsed KeyRing! - * */ public class CachedPublicKeyRing extends KeyRing { @@ -57,21 +57,17 @@ public class CachedPublicKeyRing extends KeyRing { } @Override - public long getMasterKeyId() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data; - } catch (ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public long getMasterKeyId() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER); + return (Long) data; } /** * Find the master key id related to a given query. The id will either be extracted from the * query, which should work for all specific /key_rings/ queries, or will be queried if it can't. */ - public long extractOrGetMasterKeyId() throws PgpGeneralException { + public long extractOrGetMasterKeyId() throws NotFoundException { // try extracting from the uri first String firstSegment = mUri.getPathSegments().get(1); if (!firstSegment.equals("find")) try { @@ -83,114 +79,82 @@ public class CachedPublicKeyRing extends KeyRing { return getMasterKeyId(); } - public byte[] getFingerprint() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); - return (byte[]) data; - } catch (ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public byte[] getFingerprint() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); + return (byte[]) data; } @Override - public String getPrimaryUserId() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.USER_ID, - ProviderHelper.FIELD_TYPE_STRING); - return (String) data; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public String getPrimaryUserId() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.USER_ID, + ProviderHelper.FIELD_TYPE_STRING); + return (String) data; } - public String getPrimaryUserIdWithFallback() throws PgpGeneralException { + public String getPrimaryUserIdWithFallback() throws NotFoundException { return getPrimaryUserId(); } @Override - public boolean isRevoked() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.IS_REVOKED, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data > 0; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public boolean isRevoked() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.IS_REVOKED, + ProviderHelper.FIELD_TYPE_INTEGER); + return (Long) data > 0; } @Override - public boolean canCertify() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.HAS_CERTIFY, - ProviderHelper.FIELD_TYPE_NULL); - return !((Boolean) data); - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public boolean canCertify() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.HAS_CERTIFY, + ProviderHelper.FIELD_TYPE_NULL); + return !((Boolean) data); } @Override - public long getEncryptId() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeyRings.HAS_ENCRYPT, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public long getEncryptId() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeyRings.HAS_ENCRYPT, + ProviderHelper.FIELD_TYPE_INTEGER); + return (Long) data; } @Override - public boolean hasEncrypt() throws PgpGeneralException { + public boolean hasEncrypt() throws NotFoundException { return getEncryptId() != 0; } - /** Returns the key id which should be used for signing. - * + /** + * Returns the key id which should be used for signing. + * <p/> * This method returns keys which are actually available (ie. secret available, and not stripped, * revoked, or expired), hence only works on keyrings where a secret key is available! - * */ - public long getSecretSignId() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeyRings.HAS_SIGN, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public long getSecretSignId() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeyRings.HAS_SIGN, + ProviderHelper.FIELD_TYPE_INTEGER); + return (Long) data; } @Override - public int getVerified() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.VERIFIED, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Integer) data; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public int getVerified() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.VERIFIED, + ProviderHelper.FIELD_TYPE_INTEGER); + return (Integer) data; } - public boolean hasAnySecret() throws PgpGeneralException { - try { - Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.HAS_ANY_SECRET, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data > 0; - } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); - } + public boolean hasAnySecret() throws NotFoundException { + Object data = mProviderHelper.getGenericData(mUri, + KeychainContract.KeyRings.HAS_ANY_SECRET, + ProviderHelper.FIELD_TYPE_INTEGER); + return (Long) data > 0; } - private Cursor getSubkeys() throws PgpGeneralException { + private Cursor getSubkeys() throws NotFoundException { Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null); } |