diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionResult.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionResult.java index 566238d3..d1bc3d7f 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionResult.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionResult.java @@ -11,6 +11,7 @@ import java.util.Set; import javax.annotation.Nonnull; import org.bouncycastle.openpgp.PGPLiteralData; +import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.StreamEncoding; @@ -130,6 +131,25 @@ public final class EncryptionResult { return PGPLiteralData.CONSOLE.equals(getFileName()); } + /** + * Returns true, if the message was encrypted for at least one subkey of the given certificate. + * + * @param certificate certificate + * @return true if encrypted for 1+ subkeys, false otherwise. + */ + public boolean isEncryptedFor(PGPPublicKeyRing certificate) { + for (SubkeyIdentifier recipient : recipients) { + if (certificate.getPublicKey().getKeyID() != recipient.getPrimaryKeyId()) { + continue; + } + + if (certificate.getPublicKey(recipient.getSubkeyId()) != null) { + return true; + } + } + return false; + } + /** * Create a builder for the encryption result class. *