From b3f56c927b47565bdaa7e3b4ea2a8a214aa56652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 9 Oct 2014 00:59:45 +0200 Subject: Revert "Replace PgpGeneralException with NotFoundException where appropriate" This reverts commit 49b4ff63122988dc1587844e6b4b2ee5d0855385. --- .../keychain/pgp/CanonicalizedKeyRing.java | 16 ++++++++-------- .../keychain/pgp/CanonicalizedPublicKeyRing.java | 10 +++++----- .../keychain/pgp/CanonicalizedSecretKey.java | 5 +---- .../org/sufficientlysecure/keychain/pgp/KeyRing.java | 20 ++++++++++---------- .../keychain/pgp/OpenPgpSignatureResultBuilder.java | 3 +-- .../keychain/pgp/PgpSignEncrypt.java | 13 +++++-------- 6 files changed, 30 insertions(+), 37 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java index cc0de1e34..08b7316aa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java @@ -19,7 +19,7 @@ package org.sufficientlysecure.keychain.pgp; import org.spongycastle.openpgp.PGPKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.util.IterableIterator; import java.io.IOException; @@ -56,11 +56,11 @@ public abstract class CanonicalizedKeyRing extends KeyRing { return getRing().getPublicKey().getFingerprint(); } - public String getPrimaryUserId() throws NotFoundException { + public String getPrimaryUserId() throws PgpGeneralException { return getPublicKey().getPrimaryUserId(); } - public String getPrimaryUserIdWithFallback() throws NotFoundException { + public String getPrimaryUserIdWithFallback() throws PgpGeneralException { return getPublicKey().getPrimaryUserIdWithFallback(); } @@ -87,24 +87,24 @@ public abstract class CanonicalizedKeyRing extends KeyRing { return creationDate.after(now) || (expiryDate != null && expiryDate.before(now)); } - public boolean canCertify() throws NotFoundException { + public boolean canCertify() throws PgpGeneralException { return getRing().getPublicKey().isEncryptionKey(); } - public long getEncryptId() throws NotFoundException { + public long getEncryptId() throws PgpGeneralException { for(CanonicalizedPublicKey key : publicKeyIterator()) { if (key.canEncrypt() && key.isValid()) { return key.getKeyId(); } } - throw new NotFoundException("No valid encryption key found!"); + throw new PgpGeneralException("No valid encryption key found!"); } - public boolean hasEncrypt() throws NotFoundException { + public boolean hasEncrypt() throws PgpGeneralException { try { getEncryptId(); return true; - } catch(NotFoundException e) { + } catch(PgpGeneralException e) { return false; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java index 68ac7c133..77c967c65 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java @@ -21,7 +21,7 @@ package org.sufficientlysecure.keychain.pgp; import org.spongycastle.openpgp.PGPObjectFactory; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.util.IterableIterator; import java.io.IOException; @@ -61,16 +61,16 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing { } /** Getter that returns the subkey that should be used for signing. */ - CanonicalizedPublicKey getEncryptionSubKey() throws NotFoundException { + CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException { PGPPublicKey key = getRing().getPublicKey(getEncryptId()); - if (key != null) { + if(key != null) { CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key); if(!cKey.canEncrypt()) { - throw new NotFoundException("key error"); + throw new PgpGeneralException("key error"); } return cKey; } - throw new NotFoundException("no encryption key available"); + throw new PgpGeneralException("no encryption key available"); } public IterableIterator publicKeyIterator() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 48d8dbeb9..595f37872 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -41,7 +41,6 @@ import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -255,10 +254,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { spGen.setSignatureCreationTime(false, nfcCreationTimestamp); signatureGenerator.setHashedSubpackets(spGen.generate()); return signatureGenerator; - } catch (ProviderHelper.NotFoundException e) { - // TODO: simply throw PGPException! - throw new PgpGeneralException("Error initializing signature!", e); } catch (PGPException e) { + // TODO: simply throw PGPException! throw new PgpGeneralException("Error initializing signature!", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java index 17d20a326..b682378e9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java @@ -20,7 +20,7 @@ package org.sufficientlysecure.keychain.pgp; import android.text.TextUtils; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -38,25 +38,25 @@ import java.util.regex.Pattern; */ public abstract class KeyRing { - abstract public long getMasterKeyId() throws NotFoundException; + abstract public long getMasterKeyId() throws PgpGeneralException; - abstract public String getPrimaryUserId() throws NotFoundException; + abstract public String getPrimaryUserId() throws PgpGeneralException; - abstract public String getPrimaryUserIdWithFallback() throws NotFoundException; + abstract public String getPrimaryUserIdWithFallback() throws PgpGeneralException; - public String[] getSplitPrimaryUserIdWithFallback() throws NotFoundException { + public String[] getSplitPrimaryUserIdWithFallback() throws PgpGeneralException { return splitUserId(getPrimaryUserIdWithFallback()); } - abstract public boolean isRevoked() throws NotFoundException; + abstract public boolean isRevoked() throws PgpGeneralException; - abstract public boolean canCertify() throws NotFoundException; + abstract public boolean canCertify() throws PgpGeneralException; - abstract public long getEncryptId() throws NotFoundException; + abstract public long getEncryptId() throws PgpGeneralException; - abstract public boolean hasEncrypt() throws NotFoundException; + abstract public boolean hasEncrypt() throws PgpGeneralException; - abstract public int getVerified() throws NotFoundException; + abstract public int getVerified() throws PgpGeneralException; private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java index f0bf97018..bd7606194 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.pgp; import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; @@ -97,7 +96,7 @@ public class OpenPgpSignatureResultBuilder { setKeyId(signingRing.getMasterKeyId()); try { setPrimaryUserId(signingRing.getPrimaryUserIdWithFallback()); - } catch (ProviderHelper.NotFoundException e) { + } catch (PgpGeneralException e) { Log.d(Constants.TAG, "No primary user id in keyring with master key id " + signingRing.getMasterKeyId()); } setSignatureKeyCertified(signingRing.getVerified() > 0); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 00696d150..40e265253 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -385,22 +385,19 @@ public class PgpSignEncrypt { // Asymmetric encryption for (long id : mEncryptionMasterKeyIds) { - CanonicalizedPublicKeyRing keyRing = null; try { - keyRing = mProviderHelper.getCanonicalizedPublicKeyRing( + CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing( KeyRings.buildUnifiedKeyRingUri(id)); - } catch (ProviderHelper.NotFoundException e) { - log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1, - KeyFormattingUtils.convertKeyIdToHex(id)); - } - try { CanonicalizedPublicKey key = keyRing.getEncryptionSubKey(); cPk.addMethod(key.getPubKeyEncryptionGenerator()); log.add(LogType.MSG_SE_KEY_OK, indent + 1, KeyFormattingUtils.convertKeyIdToHex(id)); - } catch (ProviderHelper.NotFoundException e) { + } catch (PgpGeneralException e) { log.add(LogType.MSG_SE_KEY_WARN, indent + 1, KeyFormattingUtils.convertKeyIdToHex(id)); + } catch (ProviderHelper.NotFoundException e) { + log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1, + KeyFormattingUtils.convertKeyIdToHex(id)); } } } -- cgit v1.2.3