Add support for RegularExpression subpackets (fixes #246)

This commit is contained in:
Paul Schaub 2022-04-07 20:47:47 +02:00
parent 7710845454
commit e4bccaf58d
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
3 changed files with 35 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import org.bouncycastle.bcpg.sig.IssuerFingerprint;
import org.bouncycastle.bcpg.sig.IssuerKeyID; import org.bouncycastle.bcpg.sig.IssuerKeyID;
import org.bouncycastle.bcpg.sig.NotationData; import org.bouncycastle.bcpg.sig.NotationData;
import org.bouncycastle.bcpg.sig.PolicyURI; import org.bouncycastle.bcpg.sig.PolicyURI;
import org.bouncycastle.bcpg.sig.RegularExpression;
import org.bouncycastle.bcpg.sig.Revocable; import org.bouncycastle.bcpg.sig.Revocable;
import org.bouncycastle.bcpg.sig.SignatureCreationTime; import org.bouncycastle.bcpg.sig.SignatureCreationTime;
import org.bouncycastle.bcpg.sig.SignatureExpirationTime; import org.bouncycastle.bcpg.sig.SignatureExpirationTime;
@ -96,6 +97,12 @@ public interface BaseSignatureSubpackets {
BaseSignatureSubpackets setPolicyUrl(@Nullable PolicyURI policyUrl); BaseSignatureSubpackets setPolicyUrl(@Nullable PolicyURI policyUrl);
BaseSignatureSubpackets setRegularExpression(@Nonnull String regex);
BaseSignatureSubpackets setRegularExpression(boolean isCritical, @Nonnull String regex);
BaseSignatureSubpackets setRegularExpression(@Nullable RegularExpression regex);
BaseSignatureSubpackets setRevocable(boolean revocable); BaseSignatureSubpackets setRevocable(boolean revocable);
BaseSignatureSubpackets setRevocable(boolean isCritical, boolean isRevocable); BaseSignatureSubpackets setRevocable(boolean isCritical, boolean isRevocable);

View File

@ -30,6 +30,7 @@ import org.bouncycastle.bcpg.sig.NotationData;
import org.bouncycastle.bcpg.sig.PolicyURI; import org.bouncycastle.bcpg.sig.PolicyURI;
import org.bouncycastle.bcpg.sig.PreferredAlgorithms; import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
import org.bouncycastle.bcpg.sig.PrimaryUserID; import org.bouncycastle.bcpg.sig.PrimaryUserID;
import org.bouncycastle.bcpg.sig.RegularExpression;
import org.bouncycastle.bcpg.sig.Revocable; import org.bouncycastle.bcpg.sig.Revocable;
import org.bouncycastle.bcpg.sig.RevocationKey; import org.bouncycastle.bcpg.sig.RevocationKey;
import org.bouncycastle.bcpg.sig.RevocationReason; import org.bouncycastle.bcpg.sig.RevocationReason;
@ -72,6 +73,7 @@ public class SignatureSubpackets
private KeyExpirationTime keyExpirationTime; private KeyExpirationTime keyExpirationTime;
private PolicyURI policyURI; private PolicyURI policyURI;
private PrimaryUserID primaryUserId; private PrimaryUserID primaryUserId;
private RegularExpression regularExpression;
private Revocable revocable; private Revocable revocable;
private RevocationReason revocationReason; private RevocationReason revocationReason;
private final List<SignatureSubpacket> residualSubpackets = new ArrayList<>(); private final List<SignatureSubpacket> residualSubpackets = new ArrayList<>();
@ -508,6 +510,26 @@ public class SignatureSubpackets
return policyURI; return policyURI;
} }
@Override
public BaseSignatureSubpackets setRegularExpression(@Nonnull String regex) {
return setRegularExpression(false, regex);
}
@Override
public BaseSignatureSubpackets setRegularExpression(boolean isCritical, @Nonnull String regex) {
return setRegularExpression(new RegularExpression(isCritical, regex));
}
@Override
public BaseSignatureSubpackets setRegularExpression(@Nullable RegularExpression regex) {
this.regularExpression = regex;
return this;
}
public RegularExpression getRegularExpression() {
return regularExpression;
}
@Override @Override
public SignatureSubpackets setRevocable(boolean revocable) { public SignatureSubpackets setRevocable(boolean revocable) {
return setRevocable(true, revocable); return setRevocable(true, revocable);

View File

@ -15,6 +15,7 @@ import org.bouncycastle.bcpg.sig.NotationData;
import org.bouncycastle.bcpg.sig.PolicyURI; import org.bouncycastle.bcpg.sig.PolicyURI;
import org.bouncycastle.bcpg.sig.PreferredAlgorithms; import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
import org.bouncycastle.bcpg.sig.PrimaryUserID; import org.bouncycastle.bcpg.sig.PrimaryUserID;
import org.bouncycastle.bcpg.sig.RegularExpression;
import org.bouncycastle.bcpg.sig.Revocable; import org.bouncycastle.bcpg.sig.Revocable;
import org.bouncycastle.bcpg.sig.RevocationKey; import org.bouncycastle.bcpg.sig.RevocationKey;
import org.bouncycastle.bcpg.sig.RevocationReason; import org.bouncycastle.bcpg.sig.RevocationReason;
@ -119,8 +120,11 @@ public class SignatureSubpacketsHelper {
PolicyURI policyURI = (PolicyURI) subpacket; PolicyURI policyURI = (PolicyURI) subpacket;
subpackets.setPolicyUrl(policyURI); subpackets.setPolicyUrl(policyURI);
break; break;
case regularExpression: case regularExpression:
RegularExpression regex = (RegularExpression) subpacket;
subpackets.setRegularExpression(regex);
break;
case keyServerPreferences: case keyServerPreferences:
case preferredKeyServers: case preferredKeyServers:
case placeholder: case placeholder:
@ -140,6 +144,7 @@ public class SignatureSubpacketsHelper {
addSubpacket(generator, subpackets.getSignatureExpirationTimeSubpacket()); addSubpacket(generator, subpackets.getSignatureExpirationTimeSubpacket());
addSubpacket(generator, subpackets.getExportableSubpacket()); addSubpacket(generator, subpackets.getExportableSubpacket());
addSubpacket(generator, subpackets.getPolicyURI()); addSubpacket(generator, subpackets.getPolicyURI());
addSubpacket(generator, subpackets.getRegularExpression());
for (NotationData notationData : subpackets.getNotationDataSubpackets()) { for (NotationData notationData : subpackets.getNotationDataSubpackets()) {
addSubpacket(generator, notationData); addSubpacket(generator, notationData);
} }