From 9e403c11248086268d8ef391226bb2218a06f76f Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 13 Sep 2022 20:22:12 +0200 Subject: [PATCH] Add ImplementationFactory.getSessionKeyDataDecryptorFactory() and impls --- .../implementation/BcImplementationFactory.java | 5 +++++ .../implementation/ImplementationFactory.java | 11 +++++++++++ .../implementation/JceImplementationFactory.java | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java index c8e20521..b7bbd5f9 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/BcImplementationFactory.java @@ -113,6 +113,11 @@ public class BcImplementationFactory extends ImplementationFactory { return new BcPublicKeyDataDecryptorFactory(privateKey); } + @Override + public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) { + return new BcSessionKeyDataDecryptorFactory(sessionKey); + } + @Override public PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key) { return new BcPublicKeyKeyEncryptionMethodGenerator(key); diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java index 94967dee..ebd776a6 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java @@ -32,6 +32,7 @@ import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.SessionKey; public abstract class ImplementationFactory { @@ -91,6 +92,16 @@ public abstract class ImplementationFactory { public abstract PublicKeyDataDecryptorFactory getPublicKeyDataDecryptorFactory(PGPPrivateKey privateKey); + public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(SessionKey sessionKey) { + PGPSessionKey pgpSessionKey = new PGPSessionKey( + sessionKey.getAlgorithm().getAlgorithmId(), + sessionKey.getKey() + ); + return getSessionKeyDataDecryptorFactory(pgpSessionKey); + } + + public abstract SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey); + public abstract PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key); public abstract PBEKeyEncryptionMethodGenerator getPBEKeyEncryptionMethodGenerator(Passphrase passphrase); diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java index 504b197e..f4efd11e 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/JceImplementationFactory.java @@ -103,6 +103,12 @@ public class JceImplementationFactory extends ImplementationFactory { .build(privateKey); } + @Override + public SessionKeyDataDecryptorFactory getSessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) { + return new JceSessionKeyDataDecryptorFactoryBuilder() + .build(sessionKey); + } + public PublicKeyKeyEncryptionMethodGenerator getPublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key) { return new JcePublicKeyKeyEncryptionMethodGenerator(key) .setProvider(ProviderFactory.getProvider());