1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Make ImplementationFactory methods abstract

This commit is contained in:
Paul Schaub 2021-01-23 01:09:55 +01:00
parent bec2fb5ce1
commit 59a14c2918
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 23 additions and 48 deletions

View file

@ -63,17 +63,13 @@ public abstract class ImplementationFactory {
getPGPDigestCalculator(HashAlgorithm.SHA1), passphrase); getPGPDigestCalculator(HashAlgorithm.SHA1), passphrase);
} }
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase) throws PGPException { public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase) throws PGPException;
return FACTORY_IMPLEMENTATION.getPBESecretKeyEncryptor(secretKey, passphrase);
}
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm symmetricKeyAlgorithm, PGPDigestCalculator digestCalculator, Passphrase passphrase) { public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm symmetricKeyAlgorithm,
return FACTORY_IMPLEMENTATION.getPBESecretKeyEncryptor(symmetricKeyAlgorithm, digestCalculator, passphrase); PGPDigestCalculator digestCalculator,
} Passphrase passphrase);
public PBESecretKeyDecryptor getPBESecretKeyDecryptor(Passphrase passphrase) throws PGPException { public abstract PBESecretKeyDecryptor getPBESecretKeyDecryptor(Passphrase passphrase) throws PGPException;
return FACTORY_IMPLEMENTATION.getPBESecretKeyDecryptor(passphrase);
}
public PGPDigestCalculator getPGPDigestCalculator(HashAlgorithm algorithm) throws PGPException { public PGPDigestCalculator getPGPDigestCalculator(HashAlgorithm algorithm) throws PGPException {
return getPGPDigestCalculator(algorithm.getAlgorithmId()); return getPGPDigestCalculator(algorithm.getAlgorithmId());
@ -83,59 +79,38 @@ public abstract class ImplementationFactory {
return getPGPDigestCalculatorProvider().get(algorithm); return getPGPDigestCalculatorProvider().get(algorithm);
} }
public PGPDigestCalculatorProvider getPGPDigestCalculatorProvider() throws PGPException { public abstract PGPDigestCalculatorProvider getPGPDigestCalculatorProvider() throws PGPException;
return FACTORY_IMPLEMENTATION.getPGPDigestCalculatorProvider();
}
public PGPContentVerifierBuilderProvider getPGPContentVerifierBuilderProvider() { public abstract PGPContentVerifierBuilderProvider getPGPContentVerifierBuilderProvider();
return FACTORY_IMPLEMENTATION.getPGPContentVerifierBuilderProvider();
}
public PGPContentSignerBuilder getPGPContentSignerBuilder(PublicKeyAlgorithm keyAlgorithm, HashAlgorithm hashAlgorithm) { public PGPContentSignerBuilder getPGPContentSignerBuilder(PublicKeyAlgorithm keyAlgorithm, HashAlgorithm hashAlgorithm) {
return getPGPContentSignerBuilder(keyAlgorithm.getAlgorithmId(), hashAlgorithm.getAlgorithmId()); return getPGPContentSignerBuilder(keyAlgorithm.getAlgorithmId(), hashAlgorithm.getAlgorithmId());
} }
public PGPContentSignerBuilder getPGPContentSignerBuilder(int keyAlgorithm, int hashAlgorithm) { public abstract PGPContentSignerBuilder getPGPContentSignerBuilder(int keyAlgorithm, int hashAlgorithm);
return FACTORY_IMPLEMENTATION.getPGPContentSignerBuilder(keyAlgorithm, hashAlgorithm);
}
public KeyFingerPrintCalculator getKeyFingerprintCalculator() { public abstract KeyFingerPrintCalculator getKeyFingerprintCalculator();
return FACTORY_IMPLEMENTATION.getKeyFingerprintCalculator();
}
public PBEDataDecryptorFactory getPBEDataDecryptorFactory(Passphrase passphrase) throws PGPException { public abstract PBEDataDecryptorFactory getPBEDataDecryptorFactory(Passphrase passphrase) throws PGPException;
return FACTORY_IMPLEMENTATION.getPBEDataDecryptorFactory(passphrase);
}
public PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey) { public abstract PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey);
return FACTORY_IMPLEMENTATION.getPublicKeyDataDecryptorFactory(privateKey);
}
public PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key) { public abstract PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key);
return FACTORY_IMPLEMENTATION.getPublicKeyKeyEncryptionMethodGenerator(key);
}
public PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase) { public abstract PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase);
return FACTORY_IMPLEMENTATION.getPBEKeyEncryptionMethodGenerator(passphrase);
}
public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(SymmetricKeyAlgorithm symmetricKeyAlgorithm) { public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(SymmetricKeyAlgorithm symmetricKeyAlgorithm) {
return getPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId()); return getPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId());
} }
public PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(int symmetricKeyAlgorithm) { public abstract PGPDataEncryptorBuilder getPGPDataEncryptorBuilder(int symmetricKeyAlgorithm);
return FACTORY_IMPLEMENTATION.getPGPDataEncryptorBuilder(symmetricKeyAlgorithm);
}
public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate) throws PGPException { public abstract PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, KeyPair keyPair, Date creationDate) throws PGPException;
return FACTORY_IMPLEMENTATION.getPGPKeyPair(algorithm, keyPair, creationDate);
}
public PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, AsymmetricCipherKeyPair keyPair, Date creationDate) throws PGPException, NoSuchAlgorithmException, IOException, InvalidKeySpecException { public abstract PGPKeyPair getPGPKeyPair(PublicKeyAlgorithm algorithm, AsymmetricCipherKeyPair keyPair, Date creationDate)
return FACTORY_IMPLEMENTATION.getPGPKeyPair(algorithm, keyPair, creationDate); throws PGPException, NoSuchAlgorithmException, IOException, InvalidKeySpecException;
}
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm, HashAlgorithm hashAlgorithm, int s2kCount, Passphrase passphrase) throws PGPException { public abstract PBESecretKeyEncryptor getPBESecretKeyEncryptor(SymmetricKeyAlgorithm encryptionAlgorithm,
return FACTORY_IMPLEMENTATION.getPBESecretKeyEncryptor(encryptionAlgorithm, hashAlgorithm, s2kCount, passphrase); HashAlgorithm hashAlgorithm, int s2kCount,
} Passphrase passphrase) throws PGPException;
} }

View file

@ -64,8 +64,7 @@ import org.pgpainless.util.Passphrase;
public class JceImplementationFactory extends ImplementationFactory { public class JceImplementationFactory extends ImplementationFactory {
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase) public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase) {
throws PGPException {
return new JcePBESecretKeyEncryptorBuilder(secretKey.getKeyEncryptionAlgorithm()) return new JcePBESecretKeyEncryptorBuilder(secretKey.getKeyEncryptionAlgorithm())
.setProvider(ProviderFactory.getProvider()) .setProvider(ProviderFactory.getProvider())
.build(passphrase.getChars()); .build(passphrase.getChars());

View file

@ -357,7 +357,8 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
throws NoSuchAlgorithmException, PGPException, throws NoSuchAlgorithmException, PGPException,
InvalidAlgorithmParameterException { InvalidAlgorithmParameterException {
KeyType type = spec.getKeyType(); KeyType type = spec.getKeyType();
KeyPairGenerator certKeyGenerator = KeyPairGenerator.getInstance(type.getName(), ProviderFactory.getProvider()); KeyPairGenerator certKeyGenerator = KeyPairGenerator.getInstance(type.getName(),
ProviderFactory.getProvider());
certKeyGenerator.initialize(type.getAlgorithmSpec()); certKeyGenerator.initialize(type.getAlgorithmSpec());
// Create raw Key Pair // Create raw Key Pair