mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Move getKeyLifetimeInSeconds to SignatureSubpacketsUtil and make public
This commit is contained in:
parent
b09858e186
commit
b874aee6bb
2 changed files with 21 additions and 19 deletions
|
@ -92,28 +92,10 @@ public final class SignatureSubpacketGeneratorUtil {
|
||||||
@Nonnull Date creationDate,
|
@Nonnull Date creationDate,
|
||||||
PGPSignatureSubpacketGenerator subpacketGenerator) {
|
PGPSignatureSubpacketGenerator subpacketGenerator) {
|
||||||
removeAllPacketsOfType(SignatureSubpacketTags.KEY_EXPIRE_TIME, subpacketGenerator);
|
removeAllPacketsOfType(SignatureSubpacketTags.KEY_EXPIRE_TIME, subpacketGenerator);
|
||||||
long secondsToExpire = getKeyLifetimeInSeconds(expirationDate, creationDate);
|
long secondsToExpire = SignatureSubpacketsUtil.getKeyLifetimeInSeconds(expirationDate, creationDate);
|
||||||
subpacketGenerator.setKeyExpirationTime(true, secondsToExpire);
|
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.
|
* 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.
|
* Returns false, if no {@link KeyFlags} subpacket is present.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.sig.Exportable;
|
import org.bouncycastle.bcpg.sig.Exportable;
|
||||||
|
@ -204,6 +205,25 @@ public final class SignatureSubpacketsUtil {
|
||||||
return SignatureUtils.datePlusSeconds(signingKey.getCreationTime(), subpacket.getTime());
|
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.
|
* Return the revocable subpacket of this signature.
|
||||||
* We only look for it in the hashed area of the signature.
|
* We only look for it in the hashed area of the signature.
|
||||||
|
|
Loading…
Reference in a new issue