mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
Add EncryptionResult.isEncryptedFor(certificate)
This commit is contained in:
parent
ecfa3823fb
commit
29dc20d0bc
1 changed files with 20 additions and 0 deletions
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPLiteralData;
|
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||||
import org.pgpainless.algorithm.StreamEncoding;
|
import org.pgpainless.algorithm.StreamEncoding;
|
||||||
|
@ -130,6 +131,25 @@ public final class EncryptionResult {
|
||||||
return PGPLiteralData.CONSOLE.equals(getFileName());
|
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.
|
* Create a builder for the encryption result class.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue