1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Rename KeyValidationException -> KeyValidationError

This commit is contained in:
Paul Schaub 2021-08-15 15:21:14 +02:00
parent 66293bf333
commit 1ce6632f18
5 changed files with 19 additions and 23 deletions

View file

@ -35,7 +35,7 @@ import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.exception.KeyCannotSignException; import org.pgpainless.exception.KeyCannotSignException;
import org.pgpainless.exception.KeyValidationException; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
@ -104,13 +104,13 @@ public final class SigningOptions {
* @param signingKeys collection of signing keys * @param signingKeys collection of signing keys
* @param signatureType type of signature (binary, canonical text) * @param signatureType type of signature (binary, canonical text)
* @return this * @return this
* @throws KeyValidationException if something is wrong with any of the keys * @throws KeyValidationError if something is wrong with any of the keys
* @throws PGPException if any of the keys cannot be unlocked or a signing method cannot be created * @throws PGPException if any of the keys cannot be unlocked or a signing method cannot be created
*/ */
public SigningOptions addInlineSignatures(SecretKeyRingProtector secrectKeyDecryptor, public SigningOptions addInlineSignatures(SecretKeyRingProtector secrectKeyDecryptor,
PGPSecretKeyRingCollection signingKeys, PGPSecretKeyRingCollection signingKeys,
DocumentSignatureType signatureType) DocumentSignatureType signatureType)
throws KeyValidationException, PGPException { throws KeyValidationError, PGPException {
for (PGPSecretKeyRing signingKey : signingKeys) { for (PGPSecretKeyRing signingKey : signingKeys) {
addInlineSignature(secrectKeyDecryptor, signingKey, signatureType); addInlineSignature(secrectKeyDecryptor, signingKey, signatureType);
} }
@ -125,14 +125,14 @@ public final class SigningOptions {
* @param secretKeyDecryptor decryptor to unlock the signing secret key * @param secretKeyDecryptor decryptor to unlock the signing secret key
* @param secretKey signing key * @param secretKey signing key
* @param signatureType type of signature (binary, canonical text) * @param signatureType type of signature (binary, canonical text)
* @throws KeyValidationException if something is wrong with the key * @throws KeyValidationError if something is wrong with the key
* @throws PGPException if the key cannot be unlocked or the signing method cannot be created * @throws PGPException if the key cannot be unlocked or the signing method cannot be created
* @return this * @return this
*/ */
public SigningOptions addInlineSignature(SecretKeyRingProtector secretKeyDecryptor, public SigningOptions addInlineSignature(SecretKeyRingProtector secretKeyDecryptor,
PGPSecretKeyRing secretKey, PGPSecretKeyRing secretKey,
DocumentSignatureType signatureType) DocumentSignatureType signatureType)
throws KeyValidationException, PGPException { throws KeyValidationError, PGPException {
return addInlineSignature(secretKeyDecryptor, secretKey, null, signatureType); return addInlineSignature(secretKeyDecryptor, secretKey, null, signatureType);
} }
@ -148,19 +148,17 @@ public final class SigningOptions {
* @param userId user-id of the signer * @param userId user-id of the signer
* @param signatureType signature type (binary, canonical text) * @param signatureType signature type (binary, canonical text)
* @return this * @return this
* @throws KeyValidationException if the key is invalid * @throws KeyValidationError if the key is invalid
* @throws PGPException if the key cannot be unlocked or the signing method cannot be created * @throws PGPException if the key cannot be unlocked or the signing method cannot be created
*/ */
public SigningOptions addInlineSignature(SecretKeyRingProtector secretKeyDecryptor, public SigningOptions addInlineSignature(SecretKeyRingProtector secretKeyDecryptor,
PGPSecretKeyRing secretKey, PGPSecretKeyRing secretKey,
String userId, String userId,
DocumentSignatureType signatureType) DocumentSignatureType signatureType)
throws KeyValidationException, PGPException { throws KeyValidationError, PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date()); KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date());
if (userId != null) { if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
if (!keyRingInfo.isUserIdValid(userId)) { throw new KeyValidationError(userId, keyRingInfo.getLatestUserIdCertification(userId), keyRingInfo.getUserIdRevocation(userId));
throw new KeyValidationException(userId, keyRingInfo.getLatestUserIdCertification(userId), keyRingInfo.getUserIdRevocation(userId));
}
} }
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys(); List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
@ -238,10 +236,8 @@ public final class SigningOptions {
DocumentSignatureType signatureType) DocumentSignatureType signatureType)
throws PGPException { throws PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date()); KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date());
if (userId != null) { if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
if (!keyRingInfo.isUserIdValid(userId)) { throw new KeyValidationError(userId, keyRingInfo.getLatestUserIdCertification(userId), keyRingInfo.getUserIdRevocation(userId));
throw new KeyValidationException(userId, keyRingInfo.getLatestUserIdCertification(userId), keyRingInfo.getUserIdRevocation(userId));
}
} }
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys(); List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();

View file

@ -17,9 +17,9 @@ package org.pgpainless.exception;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
public class KeyValidationException extends AssertionError { public class KeyValidationError extends AssertionError {
public KeyValidationException(String userId, PGPSignature userIdSig, PGPSignature userIdRevocation) { public KeyValidationError(String userId, PGPSignature userIdSig, PGPSignature userIdRevocation) {
super("User-ID '" + userId + "' is not valid: Sig: " + userIdSig + " Rev: " + userIdRevocation); super("User-ID '" + userId + "' is not valid: Sig: " + userIdSig + " Rev: " + userIdRevocation);
} }
} }

View file

@ -47,7 +47,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.exception.KeyValidationException; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;

View file

@ -39,7 +39,7 @@ import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.exception.KeyValidationException; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
@ -194,6 +194,6 @@ public class EncryptionOptionsTest {
@Test @Test
public void testAddRecipient_withInvalidUserId() { public void testAddRecipient_withInvalidUserId() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = new EncryptionOptions();
assertThrows(KeyValidationException.class, () -> options.addRecipient(publicKeys, "invalid@user.id")); assertThrows(KeyValidationError.class, () -> options.addRecipient(publicKeys, "invalid@user.id"));
} }
} }

View file

@ -42,7 +42,7 @@ import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.exception.KeyValidationException; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
@ -121,7 +121,7 @@ public class SigningTest {
SigningOptions opts = new SigningOptions(); SigningOptions opts = new SigningOptions();
// "bob" is not a valid user-id // "bob" is not a valid user-id
assertThrows(KeyValidationException.class, assertThrows(KeyValidationError.class,
() -> opts.addInlineSignature(protector, secretKeys, "bob", DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); () -> opts.addInlineSignature(protector, secretKeys, "bob", DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
} }
@ -138,7 +138,7 @@ public class SigningTest {
SigningOptions opts = new SigningOptions(); SigningOptions opts = new SigningOptions();
// "alice" has been revoked // "alice" has been revoked
assertThrows(KeyValidationException.class, assertThrows(KeyValidationError.class,
() -> opts.addInlineSignature(protector, fSecretKeys, "alice", DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); () -> opts.addInlineSignature(protector, fSecretKeys, "alice", DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
} }
} }