1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-14 00:12:06 +01:00

Add SignatureUtils.wasIssuedBy

This commit is contained in:
Paul Schaub 2022-01-04 17:21:16 +01:00
parent c270bc3d60
commit e39b63e00e

View file

@ -33,6 +33,7 @@ import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.util.OpenPgpKeyAttributeUtil;
import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
@ -310,4 +311,18 @@ public final class SignatureUtils {
}
return list;
}
public static boolean wasIssuedBy(byte[] fingerprint, PGPSignature signature) {
if (fingerprint.length != 20) {
// Unknown fingerprint length
return false;
}
OpenPgpV4Fingerprint fp = new OpenPgpV4Fingerprint(fingerprint);
OpenPgpFingerprint issuerFp = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature);
if (issuerFp == null) {
return fp.getKeyId() == signature.getKeyID();
}
return fp.equals(issuerFp);
}
}