mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-19 02:42:05 +01:00
Add documentation to AlgorithmNegotiator classes
This commit is contained in:
parent
6f161c8336
commit
405e67c0cb
2 changed files with 52 additions and 2 deletions
|
@ -9,18 +9,51 @@ import java.util.Set;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.policy.Policy;
|
import org.pgpainless.policy.Policy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a class that negotiates {@link HashAlgorithm HashAlgorithms}.
|
||||||
|
*
|
||||||
|
* You can provide your own implementation using custom logic by implementing the
|
||||||
|
* {@link #negotiateHashAlgorithm(Set)} method.
|
||||||
|
*/
|
||||||
public interface HashAlgorithmNegotiator {
|
public interface HashAlgorithmNegotiator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick one {@link HashAlgorithm} from the ordered set of acceptable algorithms.
|
||||||
|
*
|
||||||
|
* @param orderedHashAlgorithmPreferencesSet hash algorithm preferences
|
||||||
|
* @return picked algorithms
|
||||||
|
*/
|
||||||
HashAlgorithm negotiateHashAlgorithm(Set<HashAlgorithm> orderedHashAlgorithmPreferencesSet);
|
HashAlgorithm negotiateHashAlgorithm(Set<HashAlgorithm> orderedHashAlgorithmPreferencesSet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance that negotiates {@link HashAlgorithm HashAlgorithms} used for non-revocation signatures
|
||||||
|
* based on the given {@link Policy}.
|
||||||
|
*
|
||||||
|
* @param policy algorithm policy
|
||||||
|
* @return negotiator
|
||||||
|
*/
|
||||||
static HashAlgorithmNegotiator negotiateSignatureHashAlgorithm(Policy policy) {
|
static HashAlgorithmNegotiator negotiateSignatureHashAlgorithm(Policy policy) {
|
||||||
return negotiateByPolicy(policy.getSignatureHashAlgorithmPolicy());
|
return negotiateByPolicy(policy.getSignatureHashAlgorithmPolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance that negotiates {@link HashAlgorithm HashAlgorithms} used for revocation signatures
|
||||||
|
* based on the given {@link Policy}.
|
||||||
|
*
|
||||||
|
* @param policy algorithm policy
|
||||||
|
* @return negotiator
|
||||||
|
*/
|
||||||
static HashAlgorithmNegotiator negotiateRevocationSignatureAlgorithm(Policy policy) {
|
static HashAlgorithmNegotiator negotiateRevocationSignatureAlgorithm(Policy policy) {
|
||||||
return negotiateByPolicy(policy.getRevocationSignatureHashAlgorithmPolicy());
|
return negotiateByPolicy(policy.getRevocationSignatureHashAlgorithmPolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance that negotiates {@link HashAlgorithm HashAlgorithms} based on the given
|
||||||
|
* {@link Policy.HashAlgorithmPolicy}.
|
||||||
|
*
|
||||||
|
* @param hashAlgorithmPolicy algorithm policy for hash algorithms
|
||||||
|
* @return negotiator
|
||||||
|
*/
|
||||||
static HashAlgorithmNegotiator negotiateByPolicy(Policy.HashAlgorithmPolicy hashAlgorithmPolicy) {
|
static HashAlgorithmNegotiator negotiateByPolicy(Policy.HashAlgorithmPolicy hashAlgorithmPolicy) {
|
||||||
return new HashAlgorithmNegotiator() {
|
return new HashAlgorithmNegotiator() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,18 +22,35 @@ public interface SymmetricKeyAlgorithmNegotiator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negotiate a symmetric encryption algorithm.
|
* Negotiate a symmetric encryption algorithm.
|
||||||
|
* If the override is non-null, it will be returned instead of performing an actual negotiation.
|
||||||
|
* Otherwise, the list of ordered sets containing the preferences of different recipient keys will be
|
||||||
|
* used to determine a suitable symmetric encryption algorithm.
|
||||||
*
|
*
|
||||||
* @param policy algorithm policy
|
* @param policy algorithm policy
|
||||||
* @param override algorithm override (if not null, return this)
|
* @param override algorithm override (if not null, return this)
|
||||||
* @param keyPreferences list of preferences per key
|
* @param keyPreferences list of preferences per key
|
||||||
* @return negotiated algorithm
|
* @return negotiated algorithm
|
||||||
*/
|
*/
|
||||||
SymmetricKeyAlgorithm negotiate(Policy.SymmetricKeyAlgorithmPolicy policy, SymmetricKeyAlgorithm override, List<Set<SymmetricKeyAlgorithm>> keyPreferences);
|
SymmetricKeyAlgorithm negotiate(
|
||||||
|
Policy.SymmetricKeyAlgorithmPolicy policy,
|
||||||
|
SymmetricKeyAlgorithm override,
|
||||||
|
List<Set<SymmetricKeyAlgorithm>> keyPreferences);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance that negotiates a {@link SymmetricKeyAlgorithm} by selecting the most popular acceptable
|
||||||
|
* algorithm from the list of preferences.
|
||||||
|
*
|
||||||
|
* This negotiator has the best chances to select an algorithm which is understood by all recipients.
|
||||||
|
*
|
||||||
|
* @return negotiator that selects by popularity
|
||||||
|
*/
|
||||||
static SymmetricKeyAlgorithmNegotiator byPopularity() {
|
static SymmetricKeyAlgorithmNegotiator byPopularity() {
|
||||||
return new SymmetricKeyAlgorithmNegotiator() {
|
return new SymmetricKeyAlgorithmNegotiator() {
|
||||||
@Override
|
@Override
|
||||||
public SymmetricKeyAlgorithm negotiate(Policy.SymmetricKeyAlgorithmPolicy policy, SymmetricKeyAlgorithm override, List<Set<SymmetricKeyAlgorithm>> preferences) {
|
public SymmetricKeyAlgorithm negotiate(
|
||||||
|
Policy.SymmetricKeyAlgorithmPolicy policy,
|
||||||
|
SymmetricKeyAlgorithm override,
|
||||||
|
List<Set<SymmetricKeyAlgorithm>> preferences) {
|
||||||
if (override == SymmetricKeyAlgorithm.NULL) {
|
if (override == SymmetricKeyAlgorithm.NULL) {
|
||||||
throw new IllegalArgumentException("Algorithm override cannot be NULL (plaintext).");
|
throw new IllegalArgumentException("Algorithm override cannot be NULL (plaintext).");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue