1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-25 22:02:05 +01:00

Allow overriding evluation date in SigningOptions

This commit is contained in:
Paul Schaub 2023-08-03 14:57:31 +02:00
parent 16a4836f8a
commit db7e1ce942
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -97,12 +97,24 @@ public final class SigningOptions {
private final Map<SubkeyIdentifier, SigningMethod> signingMethods = new HashMap<>();
private HashAlgorithm hashAlgorithmOverride;
private Date evaluationDate = new Date();
@Nonnull
public static SigningOptions get() {
return new SigningOptions();
}
/**
* Override the evaluation date for signing keys with the given date.
*
* @param evaluationDate new evaluation date
* @return this
*/
public SigningOptions setEvaluationDate(@Nonnull Date evaluationDate) {
this.evaluationDate = evaluationDate;
return this;
}
/**
* Sign the message using an inline signature made by the provided signing key.
*
@ -212,7 +224,7 @@ public final class SigningOptions {
@Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback)
throws KeyException, PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date());
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
throw new KeyException.UnboundUserIdException(
OpenPgpFingerprint.of(secretKey),
@ -280,7 +292,7 @@ public final class SigningOptions {
long keyId,
@Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException {
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey);
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
if (signingPubKeys.isEmpty()) {
@ -418,7 +430,7 @@ public final class SigningOptions {
@Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketCallback)
throws PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date());
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
throw new KeyException.UnboundUserIdException(
OpenPgpFingerprint.of(secretKey),
@ -485,7 +497,7 @@ public final class SigningOptions {
long keyId,
@Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException {
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey);
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
if (signingPubKeys.isEmpty()) {