Replace PgpGeneralException with NotFoundException where appropriate
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
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 PgpGeneralException {
|
||||
public String getPrimaryUserId() throws NotFoundException {
|
||||
return getPublicKey().getPrimaryUserId();
|
||||
}
|
||||
|
||||
public String getPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||
public String getPrimaryUserIdWithFallback() throws NotFoundException {
|
||||
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 PgpGeneralException {
|
||||
public boolean canCertify() throws NotFoundException {
|
||||
return getRing().getPublicKey().isEncryptionKey();
|
||||
}
|
||||
|
||||
public long getEncryptId() throws PgpGeneralException {
|
||||
public long getEncryptId() throws NotFoundException {
|
||||
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
||||
if (key.canEncrypt() && key.isValid()) {
|
||||
return key.getKeyId();
|
||||
}
|
||||
}
|
||||
throw new PgpGeneralException("No valid encryption key found!");
|
||||
throw new NotFoundException("No valid encryption key found!");
|
||||
}
|
||||
|
||||
public boolean hasEncrypt() throws PgpGeneralException {
|
||||
public boolean hasEncrypt() throws NotFoundException {
|
||||
try {
|
||||
getEncryptId();
|
||||
return true;
|
||||
} catch(PgpGeneralException e) {
|
||||
} catch(NotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
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 PgpGeneralException {
|
||||
CanonicalizedPublicKey getEncryptionSubKey() throws NotFoundException {
|
||||
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
||||
if(key != null) {
|
||||
if (key != null) {
|
||||
CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key);
|
||||
if(!cKey.canEncrypt()) {
|
||||
throw new PgpGeneralException("key error");
|
||||
throw new NotFoundException("key error");
|
||||
}
|
||||
return cKey;
|
||||
}
|
||||
throw new PgpGeneralException("no encryption key available");
|
||||
throw new NotFoundException("no encryption key available");
|
||||
}
|
||||
|
||||
public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() {
|
||||
|
||||
@@ -41,6 +41,7 @@ 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;
|
||||
|
||||
@@ -254,9 +255,11 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
|
||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||
return signatureGenerator;
|
||||
} catch (PGPException e) {
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
// TODO: simply throw PGPException!
|
||||
throw new PgpGeneralException("Error initializing signature!", e);
|
||||
} catch (PGPException e) {
|
||||
throw new PgpGeneralException("Error initializing signature!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
|
||||
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 PgpGeneralException;
|
||||
abstract public long getMasterKeyId() throws NotFoundException;
|
||||
|
||||
abstract public String getPrimaryUserId() throws PgpGeneralException;
|
||||
abstract public String getPrimaryUserId() throws NotFoundException;
|
||||
|
||||
abstract public String getPrimaryUserIdWithFallback() throws PgpGeneralException;
|
||||
abstract public String getPrimaryUserIdWithFallback() throws NotFoundException;
|
||||
|
||||
public String[] getSplitPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||
public String[] getSplitPrimaryUserIdWithFallback() throws NotFoundException {
|
||||
return splitUserId(getPrimaryUserIdWithFallback());
|
||||
}
|
||||
|
||||
abstract public boolean isRevoked() throws PgpGeneralException;
|
||||
abstract public boolean isRevoked() throws NotFoundException;
|
||||
|
||||
abstract public boolean canCertify() throws PgpGeneralException;
|
||||
abstract public boolean canCertify() throws NotFoundException;
|
||||
|
||||
abstract public long getEncryptId() throws PgpGeneralException;
|
||||
abstract public long getEncryptId() throws NotFoundException;
|
||||
|
||||
abstract public boolean hasEncrypt() throws PgpGeneralException;
|
||||
abstract public boolean hasEncrypt() throws NotFoundException;
|
||||
|
||||
abstract public int getVerified() throws PgpGeneralException;
|
||||
abstract public int getVerified() throws NotFoundException;
|
||||
|
||||
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ 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;
|
||||
@@ -96,7 +97,7 @@ public class OpenPgpSignatureResultBuilder {
|
||||
setKeyId(signingRing.getMasterKeyId());
|
||||
try {
|
||||
setPrimaryUserId(signingRing.getPrimaryUserIdWithFallback());
|
||||
} catch (PgpGeneralException e) {
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.d(Constants.TAG, "No primary user id in keyring with master key id " + signingRing.getMasterKeyId());
|
||||
}
|
||||
setSignatureKeyCertified(signingRing.getVerified() > 0);
|
||||
|
||||
@@ -385,18 +385,21 @@ public class PgpSignEncrypt {
|
||||
|
||||
// Asymmetric encryption
|
||||
for (long id : mEncryptionMasterKeyIds) {
|
||||
CanonicalizedPublicKeyRing keyRing = null;
|
||||
try {
|
||||
CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
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 (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,
|
||||
log.add(LogType.MSG_SE_KEY_WARN, indent + 1,
|
||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user