From db7e1ce9423f53f2de5bb6fa353159ab60fee154 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 3 Aug 2023 14:57:31 +0200 Subject: [PATCH] Allow overriding evluation date in SigningOptions --- .../encryption_signing/SigningOptions.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java index 589e8d92..34d4bbcf 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java @@ -97,12 +97,24 @@ public final class SigningOptions { private final Map 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 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 signingPubKeys = keyRingInfo.getSigningSubkeys(); if (signingPubKeys.isEmpty()) {