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