From 90626a8a764349e3cc0f1c4c79a6d864c4e4dff1 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 19 Jun 2023 10:56:42 +0200 Subject: [PATCH] Add SignatureSubpacketsUtil.getRegularExpressions() --- .../subpackets/SignatureSubpacketsUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java index 1105a813..e69ea0a7 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java @@ -23,6 +23,7 @@ import org.bouncycastle.bcpg.sig.KeyFlags; import org.bouncycastle.bcpg.sig.NotationData; import org.bouncycastle.bcpg.sig.PreferredAlgorithms; import org.bouncycastle.bcpg.sig.PrimaryUserID; +import org.bouncycastle.bcpg.sig.RegularExpression; import org.bouncycastle.bcpg.sig.Revocable; import org.bouncycastle.bcpg.sig.RevocationKey; import org.bouncycastle.bcpg.sig.RevocationReason; @@ -540,6 +541,23 @@ public final class SignatureSubpacketsUtil { return hashed(signature, SignatureSubpacket.trustSignature); } + /** + * Return all regular expression subpackets from the hashed area of the given signature. + * + * @param signature signature + * @return list of regular expressions + */ + public static List getRegularExpressions(PGPSignature signature) { + org.bouncycastle.bcpg.SignatureSubpacket[] subpackets = signature.getHashedSubPackets() + .getSubpackets(SignatureSubpacket.regularExpression.getCode()); + List regularExpressions = new ArrayList<>(subpackets.length); + for (org.bouncycastle.bcpg.SignatureSubpacket subpacket : subpackets) { + regularExpressions.add((RegularExpression) subpacket); + } + return regularExpressions; + } + + /** * Select a list of all signature subpackets of the given type, which are present in the hashed area of * the given signature.