From ea03c66400655cdb5d15e89172fd51042aeba006 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 28 May 2021 23:20:25 +0200 Subject: [PATCH] Throw MissingDecryptionMethodException when missing decryption key or -passphrase --- .../DecryptionStreamFactory.java | 3 +- .../MissingDecryptionMethodException.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pgpainless-core/src/main/java/org/pgpainless/exception/MissingDecryptionMethodException.java diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStreamFactory.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStreamFactory.java index f9d302f5..978e951a 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStreamFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStreamFactory.java @@ -57,6 +57,7 @@ import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.StreamEncoding; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.exception.MessageNotIntegrityProtectedException; +import org.pgpainless.exception.MissingDecryptionMethodException; import org.pgpainless.exception.UnacceptableAlgorithmException; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; @@ -272,7 +273,7 @@ public final class DecryptionStreamFactory { } if (decryptionKey == null) { - throw new PGPException("Decryption failed - No suitable decryption key or passphrase found"); + throw new MissingDecryptionMethodException("Decryption failed - No suitable decryption key or passphrase found"); } PublicKeyDataDecryptorFactory dataDecryptor = ImplementationFactory.getInstance() diff --git a/pgpainless-core/src/main/java/org/pgpainless/exception/MissingDecryptionMethodException.java b/pgpainless-core/src/main/java/org/pgpainless/exception/MissingDecryptionMethodException.java new file mode 100644 index 00000000..ee522425 --- /dev/null +++ b/pgpainless-core/src/main/java/org/pgpainless/exception/MissingDecryptionMethodException.java @@ -0,0 +1,30 @@ +/* + * Copyright 2021 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pgpainless.exception; + +import org.bouncycastle.openpgp.PGPException; + +/** + * Exception that is thrown when decryption fails due to a missing decryption key or decryption passphrase. + * This can happen when the user does not provide the right set of keys / the right password when decrypting + * a message. + */ +public class MissingDecryptionMethodException extends PGPException { + + public MissingDecryptionMethodException(String message) { + super(message); + } +}