mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-10 06:11:08 +01:00
Simplify KeyType API
This commit is contained in:
parent
cb3190a0fc
commit
99a2fcf1c0
6 changed files with 28 additions and 15 deletions
|
|
@ -54,10 +54,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.key.collection.PGPKeyRing;
|
||||
import org.pgpainless.key.generation.type.ECDH;
|
||||
import org.pgpainless.key.generation.type.ECDSA;
|
||||
import org.pgpainless.key.generation.type.KeyType;
|
||||
import org.pgpainless.key.generation.type.RSA;
|
||||
import org.pgpainless.key.generation.type.curve.EllipticCurve;
|
||||
import org.pgpainless.key.generation.type.length.RsaLength;
|
||||
import org.pgpainless.provider.ProviderFactory;
|
||||
|
|
@ -108,7 +105,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
|||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
|
||||
WithAdditionalUserIdOrPassphrase builder = this
|
||||
.withMasterKey(
|
||||
KeySpec.getBuilder(RSA.withLength(length))
|
||||
KeySpec.getBuilder(KeyType.RSA(length))
|
||||
.withDefaultKeyFlags()
|
||||
.withDefaultAlgorithms())
|
||||
.withPrimaryUserId(userId);
|
||||
|
|
@ -156,11 +153,11 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
|||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
|
||||
WithAdditionalUserIdOrPassphrase builder = this
|
||||
.withSubKey(
|
||||
KeySpec.getBuilder(ECDH.fromCurve(EllipticCurve._P256))
|
||||
KeySpec.getBuilder(KeyType.ECDH(EllipticCurve._P256))
|
||||
.withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS)
|
||||
.withDefaultAlgorithms())
|
||||
.withMasterKey(
|
||||
KeySpec.getBuilder(ECDSA.fromCurve(EllipticCurve._P256))
|
||||
KeySpec.getBuilder(KeyType.ECDSA(EllipticCurve._P256))
|
||||
.withKeyFlags(KeyFlag.AUTHENTICATION, KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
|
||||
.withDefaultAlgorithms())
|
||||
.withPrimaryUserId(userId);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package org.pgpainless.key.generation.type;
|
|||
import java.security.spec.AlgorithmParameterSpec;
|
||||
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.key.generation.type.curve.EllipticCurve;
|
||||
import org.pgpainless.key.generation.type.length.RsaLength;
|
||||
|
||||
public interface KeyType {
|
||||
|
||||
|
|
@ -26,4 +28,18 @@ public interface KeyType {
|
|||
PublicKeyAlgorithm getAlgorithm();
|
||||
|
||||
AlgorithmParameterSpec getAlgorithmSpec();
|
||||
|
||||
static KeyType RSA(RsaLength length) {
|
||||
return RSA.withLength(length);
|
||||
}
|
||||
|
||||
static KeyType ECDH(EllipticCurve curve) {
|
||||
return ECDH.fromCurve(curve);
|
||||
}
|
||||
|
||||
static KeyType ECDSA(EllipticCurve curve) {
|
||||
return ECDSA.fromCurve(curve);
|
||||
}
|
||||
|
||||
// TODO: Decide, if we want to add ElGamal here as well?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue