1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 14:21:09 +01:00

Add KeyRingInfo.isUsableForEncryption()

This commit is contained in:
Paul Schaub 2022-03-06 14:58:36 +01:00
parent afad3fc747
commit 5b9e72d42c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 118 additions and 1 deletions

View file

@ -1009,6 +1009,25 @@ public class KeyRingInfo {
return new KeyAccessor.SubKey(this, new SubkeyIdentifier(keys, keyId)).getPreferredCompressionAlgorithms();
}
/**
* Returns true, if the certificate has at least one usable encryption subkey.
*
* @return true if usable for encryption
*/
public boolean isUsableForEncryption() {
return isUsableForEncryption(EncryptionPurpose.ANY);
}
/**
* Returns true, if the certificate has at least one usable encryption subkey for the given purpose.
*
* @param purpose purpose of encryption
* @return true if usable for encryption
*/
public boolean isUsableForEncryption(@Nonnull EncryptionPurpose purpose) {
return !getEncryptionSubkeys(purpose).isEmpty();
}
private KeyAccessor getKeyAccessor(@Nullable String userId, long keyID) {
if (getPublicKey(keyID) == null) {
throw new NoSuchElementException("No subkey with key id " + Long.toHexString(keyID) + " found on this key.");