Package org.pgpainless.signature
Class SignatureUtils
- java.lang.Object
-
- org.pgpainless.signature.SignatureUtils
-
public final class SignatureUtils extends java.lang.Object
Utility methods related to signatures.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_ITERATIONS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Date
datePlusSeconds(java.util.Date date, long seconds)
Return a new date which represents the given date plus the given amount of seconds added.static long
determineIssuerKeyId(org.bouncycastle.openpgp.PGPSignature signature)
Determine the issuer key-id of aPGPSignature
.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
get3rdPartyCertificationsFor(java.lang.String userId, org.bouncycastle.openpgp.PGPPublicKeyRing key)
static java.util.List<org.bouncycastle.openpgp.PGPSignature>
getDelegations(org.bouncycastle.openpgp.PGPPublicKeyRing key)
static java.util.Date
getKeyExpirationDate(java.util.Date keyCreationDate, org.bouncycastle.openpgp.PGPSignature signature)
Extract and return the key expiration date value from the given signature.static java.lang.String
getSignatureDigestPrefix(org.bouncycastle.openpgp.PGPSignature signature)
Return the digest prefix of the signature as hex-encoded String.static java.util.Date
getSignatureExpirationDate(org.bouncycastle.openpgp.PGPSignature signature)
Return the expiration date of the signature.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
getSignaturesOverUserIdBy(org.bouncycastle.openpgp.PGPPublicKey key, java.lang.String userId, long issuerKeyId)
Extract all signatures from the givenstatic boolean
isHardRevocation(org.bouncycastle.openpgp.PGPSignature signature)
Return true if the provided signature is a hard revocation.static boolean
isSignatureExpired(org.bouncycastle.openpgp.PGPSignature signature)
Return true, if the expiration date of thePGPSignature
lays in the past.static boolean
isSignatureExpired(org.bouncycastle.openpgp.PGPSignature signature, java.util.Date comparisonDate)
Return true, if the expiration date of the givenPGPSignature
is past the given comparisonDate
.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
readSignatures(byte[] encodedSignatures)
Read a single, or a list ofPGPSignatures
and return them as aList
.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
readSignatures(java.io.InputStream inputStream)
Read and returnPGPSignatures
.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
readSignatures(java.io.InputStream inputStream, int maxIterations)
Read and returnPGPSignatures
.static java.util.List<org.bouncycastle.openpgp.PGPSignature>
readSignatures(java.lang.String encodedSignatures)
Parse an ASCII encoded list of OpenPGP signatures into aPGPSignatureList
and return it as aList
.static boolean
wasIssuedBy(byte[] fingerprint, org.bouncycastle.openpgp.PGPSignature signature)
-
-
-
Field Detail
-
MAX_ITERATIONS
public static final int MAX_ITERATIONS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getKeyExpirationDate
public static java.util.Date getKeyExpirationDate(java.util.Date keyCreationDate, org.bouncycastle.openpgp.PGPSignature signature)
Extract and return the key expiration date value from the given signature. If the signature does not carry aKeyExpirationTime
subpacket, return null.- Parameters:
keyCreationDate
- creation date of the keysignature
- signature- Returns:
- key expiration date as given by the signature
-
getSignatureExpirationDate
public static java.util.Date getSignatureExpirationDate(org.bouncycastle.openpgp.PGPSignature signature)
Return the expiration date of the signature. If the signature has no expiration date,datePlusSeconds(Date, long)
will return null.- Parameters:
signature
- signature- Returns:
- expiration date of the signature, or null if it does not expire.
-
datePlusSeconds
public static java.util.Date datePlusSeconds(java.util.Date date, long seconds)
Return a new date which represents the given date plus the given amount of seconds added. Since '0' is a special date value in the OpenPGP specification (e.g. '0' means no expiration for expiration dates), this method will return 'null' if seconds is 0.- Parameters:
date
- dateseconds
- number of seconds to be added- Returns:
- date plus seconds or null if seconds is '0'
-
isSignatureExpired
public static boolean isSignatureExpired(org.bouncycastle.openpgp.PGPSignature signature)
Return true, if the expiration date of thePGPSignature
lays in the past. If no expiration date is present in the signature, it is considered non-expired.- Parameters:
signature
- signature- Returns:
- true if expired, false otherwise
-
isSignatureExpired
public static boolean isSignatureExpired(org.bouncycastle.openpgp.PGPSignature signature, java.util.Date comparisonDate)
Return true, if the expiration date of the givenPGPSignature
is past the given comparisonDate
. If no expiration date is present in the signature, it is considered non-expiring.- Parameters:
signature
- signaturecomparisonDate
- reference date- Returns:
- true if sig is expired at reference date, false otherwise
-
isHardRevocation
public static boolean isHardRevocation(org.bouncycastle.openpgp.PGPSignature signature)
Return true if the provided signature is a hard revocation. Hard revocations are revocation signatures which either carry a revocation reason ofRevocationAttributes.Reason.KEY_COMPROMISED
orRevocationAttributes.Reason.NO_REASON
, or no reason at all.- Parameters:
signature
- signature- Returns:
- true if signature is a hard revocation
-
readSignatures
public static java.util.List<org.bouncycastle.openpgp.PGPSignature> readSignatures(java.lang.String encodedSignatures) throws java.io.IOException, org.bouncycastle.openpgp.PGPException
Parse an ASCII encoded list of OpenPGP signatures into aPGPSignatureList
and return it as aList
.- Parameters:
encodedSignatures
- ASCII armored signature list- Returns:
- signature list
- Throws:
java.io.IOException
- if the signatures cannot be readorg.bouncycastle.openpgp.PGPException
- in case of a broken signature
-
readSignatures
public static java.util.List<org.bouncycastle.openpgp.PGPSignature> readSignatures(byte[] encodedSignatures) throws java.io.IOException, org.bouncycastle.openpgp.PGPException
Read a single, or a list ofPGPSignatures
and return them as aList
.- Parameters:
encodedSignatures
- ASCII armored or binary signatures- Returns:
- signatures
- Throws:
java.io.IOException
- if the signatures cannot be readorg.bouncycastle.openpgp.PGPException
- in case of an OpenPGP error
-
readSignatures
public static java.util.List<org.bouncycastle.openpgp.PGPSignature> readSignatures(java.io.InputStream inputStream) throws java.io.IOException, org.bouncycastle.openpgp.PGPException
Read and returnPGPSignatures
. This method can deal with signatures that may be armored, compressed and may contain marker packets.- Parameters:
inputStream
- input stream- Returns:
- list of encountered signatures
- Throws:
java.io.IOException
- in case of a stream errororg.bouncycastle.openpgp.PGPException
- in case of an OpenPGP error
-
readSignatures
public static java.util.List<org.bouncycastle.openpgp.PGPSignature> readSignatures(java.io.InputStream inputStream, int maxIterations) throws java.io.IOException
Read and returnPGPSignatures
. This method can deal with signatures that may be binary, armored and may contain marker packets.- Parameters:
inputStream
- input streammaxIterations
- number of loop iterations until reading is aborted- Returns:
- list of encountered signatures
- Throws:
java.io.IOException
- in case of a stream error
-
determineIssuerKeyId
public static long determineIssuerKeyId(org.bouncycastle.openpgp.PGPSignature signature)
Determine the issuer key-id of aPGPSignature
. This method first inspects theIssuerKeyID
subpacket of the signature and returns the key-id if present. If not, it inspects theIssuerFingerprint
packet and retrieves the key-id from the fingerprint. Otherwise, it returns 0.- Parameters:
signature
- signature- Returns:
- signatures issuing key id
-
getSignatureDigestPrefix
public static java.lang.String getSignatureDigestPrefix(org.bouncycastle.openpgp.PGPSignature signature)
Return the digest prefix of the signature as hex-encoded String.- Parameters:
signature
- signature- Returns:
- digest prefix
-
wasIssuedBy
public static boolean wasIssuedBy(byte[] fingerprint, org.bouncycastle.openpgp.PGPSignature signature)
-
getSignaturesOverUserIdBy
@Nonnull public static java.util.List<org.bouncycastle.openpgp.PGPSignature> getSignaturesOverUserIdBy(@Nonnull org.bouncycastle.openpgp.PGPPublicKey key, @Nonnull java.lang.String userId, long issuerKeyId)
Extract all signatures from the givenkey
which were issued byissuerKeyId
overuserId
.- Parameters:
key
- public keyuserId
- user-idissuerKeyId
- issuer key-id- Returns:
- (potentially empty) list of signatures
-
getDelegations
@Nonnull public static java.util.List<org.bouncycastle.openpgp.PGPSignature> getDelegations(org.bouncycastle.openpgp.PGPPublicKeyRing key)
-
get3rdPartyCertificationsFor
@Nonnull public static java.util.List<org.bouncycastle.openpgp.PGPSignature> get3rdPartyCertificationsFor(java.lang.String userId, org.bouncycastle.openpgp.PGPPublicKeyRing key)
-
-