Add EncryptionResult.isEncryptedFor(certificate)

This commit is contained in:
Paul Schaub 2022-03-15 16:52:29 +01:00
parent ecfa3823fb
commit 29dc20d0bc
1 changed files with 20 additions and 0 deletions

View File

@ -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.
*