mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-12 03:39:39 +02:00
Further sourcing of PGPObjectFactory from ImplementationProvider
This commit is contained in:
parent
60f7a9d9ec
commit
a66b45c3d2
9 changed files with 35 additions and 49 deletions
|
@ -18,15 +18,19 @@ import java.util.Date;
|
|||
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.util.PGPUtilWrapper;
|
||||
|
||||
public class PGPUtilWrapperTest {
|
||||
|
||||
@Test
|
||||
public void testGetDecoderStream() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
|
||||
public void testGetDecoderStream(ImplementationFactory implementationFactory) throws IOException {
|
||||
ImplementationFactory.setFactoryImplementation(implementationFactory);
|
||||
|
||||
ByteArrayInputStream msg = new ByteArrayInputStream("Foo\nBar".getBytes(StandardCharsets.UTF_8));
|
||||
PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator();
|
||||
|
||||
|
@ -36,7 +40,7 @@ public class PGPUtilWrapperTest {
|
|||
literalDataGenerator.close();
|
||||
|
||||
InputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
PGPObjectFactory objectFactory = new BcPGPObjectFactory(in);
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(in);
|
||||
PGPLiteralData literalData = (PGPLiteralData) objectFactory.nextObject();
|
||||
InputStream litIn = literalData.getDataStream();
|
||||
BufferedInputStream bufIn = new BufferedInputStream(litIn);
|
||||
|
|
|
@ -19,9 +19,6 @@ import org.bouncycastle.openpgp.PGPException;
|
|||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
@ -168,14 +165,12 @@ public class ChangeSecretKeyRingPassphraseTest {
|
|||
* @throws PGPException if passphrase is wrong
|
||||
*/
|
||||
private void extractPrivateKey(PGPSecretKey secretKey, Passphrase passphrase) throws PGPException {
|
||||
PGPDigestCalculatorProvider digestCalculatorProvider = new BcPGPDigestCalculatorProvider();
|
||||
if (passphrase.isEmpty() && secretKey.getKeyEncryptionAlgorithm() != SymmetricKeyAlgorithm.NULL.getAlgorithmId()) {
|
||||
throw new PGPException("Cannot unlock encrypted private key with empty passphrase.");
|
||||
} else if (!passphrase.isEmpty() && secretKey.getKeyEncryptionAlgorithm() == SymmetricKeyAlgorithm.NULL.getAlgorithmId()) {
|
||||
throw new PGPException("Cannot unlock unprotected private key with non-empty passphrase.");
|
||||
}
|
||||
PBESecretKeyDecryptor decryptor = passphrase.isEmpty() ? null : new BcPBESecretKeyDecryptorBuilder(digestCalculatorProvider)
|
||||
.build(passphrase.getChars());
|
||||
PBESecretKeyDecryptor decryptor = passphrase.isEmpty() ? null : ImplementationFactory.getInstance().getPBESecretKeyDecryptor(passphrase);
|
||||
|
||||
UnlockSecretKey.unlockSecretKey(secretKey, decryptor);
|
||||
}
|
||||
|
|
|
@ -31,9 +31,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
@ -79,7 +77,7 @@ public class OnePassSignatureBracketingTest {
|
|||
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
InputStream inputStream = PGPUtil.getDecoderStream(ciphertextIn);
|
||||
PGPObjectFactory objectFactory = new BcPGPObjectFactory(inputStream);
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(inputStream);
|
||||
|
||||
PGPOnePassSignatureList onePassSignatures = null;
|
||||
PGPSignatureList signatures = null;
|
||||
|
@ -96,9 +94,9 @@ public class OnePassSignatureBracketingTest {
|
|||
PGPPublicKeyEncryptedData publicKeyEncryptedData = (PGPPublicKeyEncryptedData) encryptedData;
|
||||
PGPSecretKey secretKey = key1.getSecretKey(publicKeyEncryptedData.getKeyID());
|
||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
PublicKeyDataDecryptorFactory decryptorFactory = new BcPublicKeyDataDecryptorFactory(privateKey);
|
||||
PublicKeyDataDecryptorFactory decryptorFactory = ImplementationFactory.getInstance().getPublicKeyDataDecryptorFactory(privateKey);
|
||||
InputStream decryptionStream = publicKeyEncryptedData.getDataStream(decryptorFactory);
|
||||
objectFactory = new BcPGPObjectFactory(decryptionStream);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decryptionStream);
|
||||
continue outerloop;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +106,7 @@ public class OnePassSignatureBracketingTest {
|
|||
} else if (next instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressed = (PGPCompressedData) next;
|
||||
InputStream decompressor = compressed.getDataStream();
|
||||
objectFactory = new PGPObjectFactory(decompressor, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decompressor);
|
||||
continue outerloop;
|
||||
} else if (next instanceof PGPLiteralData) {
|
||||
continue outerloop;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue