diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java index fe493ac7..eeb87a10 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java @@ -92,28 +92,10 @@ public final class SignatureSubpacketGeneratorUtil { @Nonnull Date creationDate, PGPSignatureSubpacketGenerator subpacketGenerator) { removeAllPacketsOfType(SignatureSubpacketTags.KEY_EXPIRE_TIME, subpacketGenerator); - long secondsToExpire = getKeyLifetimeInSeconds(expirationDate, creationDate); + long secondsToExpire = SignatureSubpacketsUtil.getKeyLifetimeInSeconds(expirationDate, creationDate); subpacketGenerator.setKeyExpirationTime(true, secondsToExpire); } - /** - * Calculate the duration in seconds until the key expires after creation. - * - * @param expirationDate new expiration date - * @param creationTime key creation time - * @return life time of the key in seconds - */ - private static long getKeyLifetimeInSeconds(Date expirationDate, @Nonnull Date creationTime) { - long secondsToExpire = 0; // 0 means "no expiration" - if (expirationDate != null) { - if (creationTime.after(expirationDate)) { - throw new IllegalArgumentException("Key MUST NOT expire before being created. (creation: " + creationTime + ", expiration: " + expirationDate + ")"); - } - secondsToExpire = (expirationDate.getTime() - creationTime.getTime()) / 1000; - } - return secondsToExpire; - } - /** * Return true, if the subpacket generator has a {@link KeyFlags} subpacket which carries the given key flag. * Returns false, if no {@link KeyFlags} subpacket is present. 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 751c9f73..d564bfce 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 @@ -11,6 +11,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.bouncycastle.bcpg.sig.Exportable; @@ -204,6 +205,25 @@ public final class SignatureSubpacketsUtil { return SignatureUtils.datePlusSeconds(signingKey.getCreationTime(), subpacket.getTime()); } + /** + * Calculate the duration in seconds until the key expires after creation. + * + * @param expirationDate new expiration date + * @param creationDate key creation time + * @return life time of the key in seconds + */ + public static long getKeyLifetimeInSeconds(@Nullable Date expirationDate, @Nonnull Date creationDate) { + long secondsToExpire = 0; // 0 means "no expiration" + if (expirationDate != null) { + if (creationDate.after(expirationDate)) { + throw new IllegalArgumentException("Key MUST NOT expire before being created. " + + "(creation: " + creationDate + ", expiration: " + expirationDate + ")"); + } + secondsToExpire = (expirationDate.getTime() - creationDate.getTime()) / 1000; + } + return secondsToExpire; + } + /** * Return the revocable subpacket of this signature. * We only look for it in the hashed area of the signature.