Package org.pgpainless.policy
Class Policy.HashAlgorithmPolicy
- java.lang.Object
-
- org.pgpainless.policy.Policy.HashAlgorithmPolicy
-
- Enclosing class:
- Policy
public static final class Policy.HashAlgorithmPolicy extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description HashAlgorithmPolicy(HashAlgorithm defaultHashAlgorithm, java.util.List<HashAlgorithm> acceptableHashAlgorithms)
Create aPolicy.HashAlgorithmPolicy
which accepts allHashAlgorithms
listed in the given list, regardless of usage date.HashAlgorithmPolicy(HashAlgorithm defaultHashAlgorithm, java.util.Map<HashAlgorithm,java.util.Date> algorithmTerminationDates)
Create aPolicy.HashAlgorithmPolicy
which accepts allHashAlgorithms
from the given map, if the queried usage date is BEFORE the respective termination date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HashAlgorithm
defaultHashAlgorithm()
Return the default hash algorithm.static Policy.HashAlgorithmPolicy
defaultRevocationSignatureHashAlgorithmPolicy()
Deprecated.not expressive - will be removed in an upcoming releasestatic Policy.HashAlgorithmPolicy
defaultSignatureAlgorithmPolicy()
Deprecated.not expressive - will be removed in an upcoming releaseboolean
isAcceptable(int algorithmId)
Return true if the given hash algorithm is currently acceptable by this policy.boolean
isAcceptable(int algorithmId, java.util.Date usageDate)
boolean
isAcceptable(HashAlgorithm hashAlgorithm)
Return true if the given hash algorithm is currently acceptable by this policy.boolean
isAcceptable(HashAlgorithm hashAlgorithm, java.util.Date usageDate)
Return true, if the given algorithm is acceptable for the given usage date.static Policy.HashAlgorithmPolicy
smartSignatureHashAlgorithmPolicy()
Policy.HashAlgorithmPolicy
which takes the date of the algorithm usage into consideration.static Policy.HashAlgorithmPolicy
static2022RevocationSignatureHashAlgorithmPolicy()
Hash algorithm policy for revocation signatures, which accepts SHA1 and SHA2 algorithms, as well as RIPEMD160.static Policy.HashAlgorithmPolicy
static2022SignatureHashAlgorithmPolicy()
Policy.HashAlgorithmPolicy
which only accepts signatures made using algorithms which are acceptable according to 2022 standards.
-
-
-
Constructor Detail
-
HashAlgorithmPolicy
public HashAlgorithmPolicy(@Nonnull HashAlgorithm defaultHashAlgorithm, @Nonnull java.util.Map<HashAlgorithm,java.util.Date> algorithmTerminationDates)
Create aPolicy.HashAlgorithmPolicy
which accepts allHashAlgorithms
from the given map, if the queried usage date is BEFORE the respective termination date. A termination date value ofnull
means no termination, resulting in the algorithm being acceptable, regardless of usage date.- Parameters:
defaultHashAlgorithm
- default hash algorithmalgorithmTerminationDates
- map of acceptable algorithms and their termination dates
-
HashAlgorithmPolicy
public HashAlgorithmPolicy(@Nonnull HashAlgorithm defaultHashAlgorithm, @Nonnull java.util.List<HashAlgorithm> acceptableHashAlgorithms)
Create aPolicy.HashAlgorithmPolicy
which accepts allHashAlgorithms
listed in the given list, regardless of usage date.- Parameters:
defaultHashAlgorithm
- default hash algorithm (e.g. used as fallback if negotiation fails)acceptableHashAlgorithms
- list of acceptable hash algorithms
-
-
Method Detail
-
defaultHashAlgorithm
public HashAlgorithm defaultHashAlgorithm()
Return the default hash algorithm. This algorithm is used as a fallback when no consensus about hash algorithms can be reached.- Returns:
- default hash algorithm
-
isAcceptable
public boolean isAcceptable(@Nonnull HashAlgorithm hashAlgorithm)
Return true if the given hash algorithm is currently acceptable by this policy.- Parameters:
hashAlgorithm
- hash algorithm- Returns:
- true if the hash algorithm is acceptable, false otherwise
-
isAcceptable
public boolean isAcceptable(int algorithmId)
Return true if the given hash algorithm is currently acceptable by this policy.- Parameters:
algorithmId
- hash algorithm- Returns:
- true if the hash algorithm is acceptable, false otherwise
-
isAcceptable
public boolean isAcceptable(@Nonnull HashAlgorithm hashAlgorithm, @Nonnull java.util.Date usageDate)
Return true, if the given algorithm is acceptable for the given usage date.- Parameters:
hashAlgorithm
- algorithmusageDate
- usage date (e.g. signature creation time)- Returns:
- acceptance
-
isAcceptable
public boolean isAcceptable(int algorithmId, @Nonnull java.util.Date usageDate)
-
defaultSignatureAlgorithmPolicy
@Deprecated public static Policy.HashAlgorithmPolicy defaultSignatureAlgorithmPolicy()
Deprecated.not expressive - will be removed in an upcoming releaseThe default signature hash algorithm policy of PGPainless. Note that this policy is only used for non-revocation signatures. For revocation signaturesdefaultRevocationSignatureHashAlgorithmPolicy()
is used instead.- Returns:
- default signature hash algorithm policy
-
smartSignatureHashAlgorithmPolicy
public static Policy.HashAlgorithmPolicy smartSignatureHashAlgorithmPolicy()
Policy.HashAlgorithmPolicy
which takes the date of the algorithm usage into consideration. If the policy has a termination date for a given algorithm, and the usage date is after that termination date, the algorithm is rejected. This policy is inspired by Sequoia-PGP's collision resistant algorithm policy.- Returns:
- smart signature algorithm policy
- See Also:
- Sequoia-PGP's Collision Resistant Algorithm Policy
-
static2022SignatureHashAlgorithmPolicy
public static Policy.HashAlgorithmPolicy static2022SignatureHashAlgorithmPolicy()
Policy.HashAlgorithmPolicy
which only accepts signatures made using algorithms which are acceptable according to 2022 standards. Particularly this policy only accepts algorithms from the SHA2 family.- Returns:
- static signature algorithm policy
-
defaultRevocationSignatureHashAlgorithmPolicy
@Deprecated public static Policy.HashAlgorithmPolicy defaultRevocationSignatureHashAlgorithmPolicy()
Deprecated.not expressive - will be removed in an upcoming releaseThe default revocation signature hash algorithm policy of PGPainless.- Returns:
- default revocation signature hash algorithm policy
-
static2022RevocationSignatureHashAlgorithmPolicy
public static Policy.HashAlgorithmPolicy static2022RevocationSignatureHashAlgorithmPolicy()
Hash algorithm policy for revocation signatures, which accepts SHA1 and SHA2 algorithms, as well as RIPEMD160.- Returns:
- static revocation signature hash algorithm policy
-
-