Revert "Replace PgpGeneralException with NotFoundException where appropriate"

This reverts commit 49b4ff6312.
This commit is contained in:
Dominik Schürmann
2014-10-09 00:59:45 +02:00
parent a13bcbbb5b
commit b3f56c927b
20 changed files with 150 additions and 119 deletions

View File

@@ -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;
}
}

View File

@@ -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<CanonicalizedPublicKey> publicKeyIterator() {

View File

@@ -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);
}
}

View File

@@ -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("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");

View File

@@ -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);

View File

@@ -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));
}
}
}