1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Add KeyRingInfo.isSigningCapable()

Fixes #307
This commit is contained in:
Paul Schaub 2022-08-09 15:08:59 +02:00
parent b9845912ee
commit bc5dc50b78
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -1051,10 +1051,36 @@ public class KeyRingInfo {
return isKeyValidlyBound(getKeyId()) && !getEncryptionSubkeys(purpose).isEmpty();
}
public boolean isUsableForSigning() {
/**
* Returns true, if the key ring is capable of signing.
* Contrary to {@link #isUsableForSigning()}, this method also returns true, if this {@link KeyRingInfo} is based
* on a key ring which has at least one valid public key marked for signing.
* The secret key is not required for the key ring to qualify as signing capable.
*
* @return true if key corresponding to the cert is capable of signing
*/
public boolean isSigningCapable() {
// check if primary-key is revoked / expired
if (!isKeyValidlyBound(getKeyId())) {
return false;
}
// check if it has signing-capable key
return !getSigningSubkeys().isEmpty();
}
/**
* Returns true, if this {@link KeyRingInfo} is based on a {@link PGPSecretKeyRing}, which has a valid signing key
* which is ready to be used (i.e. secret key is present and is not on a smart-card).
*
* If you just want to check, whether a key / certificate has signing capable subkeys,
* use {@link #isSigningCapable()} instead.
*
* @return true if key is ready to be used for signing
*/
public boolean isUsableForSigning() {
if (!isSigningCapable()) {
return false;
}
List<PGPPublicKey> signingKeys = getSigningSubkeys();
for (PGPPublicKey pk : signingKeys) {