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 Object

## Constructor Summary

Constructors
Constructor
Description
`HashAlgorithmPolicy(HashAlgorithm defaultHashAlgorithm, List<HashAlgorithm> acceptableHashAlgorithms)`
Create a `Policy.HashAlgorithmPolicy` which accepts all `HashAlgorithms` listed in the given list, regardless of usage date.
`HashAlgorithmPolicy(HashAlgorithm defaultHashAlgorithm, Map<HashAlgorithm,Date> algorithmTerminationDates)`
Create a `Policy.HashAlgorithmPolicy` which accepts all `HashAlgorithms` from the given map, if the queried usage date is BEFORE the respective termination date.

## Method Summary

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 release
`static Policy.HashAlgorithmPolicy`
`defaultSignatureAlgorithmPolicy()`
Deprecated.
not expressive - will be removed in an upcoming release
`boolean`
`isAcceptable(int algorithmId)`
Return true if the given hash algorithm is currently acceptable by this policy.
`boolean`
`isAcceptable(int algorithmId, Date usageDate)`
`boolean`
`isAcceptable(HashAlgorithm hashAlgorithm)`
Return true if the given hash algorithm is currently acceptable by this policy.
`boolean`
`isAcceptable(HashAlgorithm hashAlgorithm, 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### HashAlgorithmPolicy

public HashAlgorithmPolicy(@Nonnull HashAlgorithm defaultHashAlgorithm, @Nonnull Map<HashAlgorithm,Date> algorithmTerminationDates)
Create a `Policy.HashAlgorithmPolicy` which accepts all `HashAlgorithms` from the given map, if the queried usage date is BEFORE the respective termination date. A termination date value of

    null

means no termination, resulting in the algorithm being acceptable, regardless of usage date.

Parameters:
  `defaultHashAlgorithm` - default hash algorithm
  `algorithmTerminationDates` - map of acceptable algorithms and their termination dates

### HashAlgorithmPolicy

public HashAlgorithmPolicy(@Nonnull HashAlgorithm defaultHashAlgorithm, @Nonnull List<HashAlgorithm> acceptableHashAlgorithms)
Create a `Policy.HashAlgorithmPolicy` which accepts all `HashAlgorithms` 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 Details

### 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 Date usageDate)
Return true, if the given algorithm is acceptable for the given usage date.

Parameters:
  `hashAlgorithm` - algorithm
  `usageDate` - usage date (e.g. signature creation time)
Returns:
  acceptance

### isAcceptable

public boolean isAcceptable(int algorithmId, @Nonnull Date usageDate)

### defaultSignatureAlgorithmPolicy

@Deprecated public static Policy.HashAlgorithmPolicy defaultSignatureAlgorithmPolicy()
Deprecated.
not expressive - will be removed in an upcoming release
The default signature hash algorithm policy of PGPainless. Note that this policy is only used for non-revocation signatures. For revocation signatures `defaultRevocationSignatureHashAlgorithmPolicy()` 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 release
The 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