Skip to content

Commit 2d394ca

Browse files
committed
PGPSignature: Add isRevocation, isHardRevocation methods
1 parent 15ae18e commit 2d394ca

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPSignature.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.bouncycastle.bcpg.TrustPacket;
2424
import org.bouncycastle.bcpg.sig.IssuerFingerprint;
2525
import org.bouncycastle.bcpg.sig.IssuerKeyID;
26+
import org.bouncycastle.bcpg.sig.RevocationReason;
27+
import org.bouncycastle.bcpg.sig.RevocationReasonTags;
2628
import org.bouncycastle.math.ec.rfc8032.Ed25519;
2729
import org.bouncycastle.math.ec.rfc8032.Ed448;
2830
import org.bouncycastle.openpgp.operator.PGPContentVerifier;
@@ -905,6 +907,37 @@ public static boolean isCertification(int signatureType)
905907
|| PGPSignature.POSITIVE_CERTIFICATION == signatureType;
906908
}
907909

910+
public static boolean isRevocation(int signatureType)
911+
{
912+
return PGPSignature.KEY_REVOCATION == signatureType
913+
|| PGPSignature.CERTIFICATION_REVOCATION == signatureType
914+
|| PGPSignature.SUBKEY_REVOCATION == signatureType;
915+
}
916+
917+
public boolean isHardRevocation()
918+
{
919+
if (!isRevocation(getSignatureType()))
920+
{
921+
return false; // no revocation
922+
}
923+
924+
if (!hasSubpackets())
925+
{
926+
return true; // consider missing subpackets (and therefore missing reason) as hard revocation
927+
}
928+
929+
// only consider reasons from the hashed packet area
930+
RevocationReason reason = getHashedSubPackets() != null ?
931+
getHashedSubPackets().getRevocationReason() : null;
932+
if (reason == null)
933+
{
934+
return true; // missing reason packet is hard
935+
}
936+
937+
return reason.getRevocationReason() == RevocationReasonTags.NO_REASON // No reason is hard
938+
|| reason.getRevocationReason() == RevocationReasonTags.KEY_COMPROMISED; // key compromise is hard
939+
}
940+
908941
/**
909942
* Return true, if the cryptographic signature encoding of the two signatures match.
910943
*

0 commit comments

Comments
 (0)