mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 02:39:39 +02:00
Remove ImplementationFactory in favor of BCs OpenPGPImplementation
This commit is contained in:
parent
321053d66e
commit
42c262a99f
48 changed files with 303 additions and 550 deletions
|
@ -13,11 +13,11 @@ import org.bouncycastle.openpgp.PGPException
|
|||
import org.bouncycastle.openpgp.PGPLiteralData
|
||||
import org.bouncycastle.openpgp.PGPOnePassSignatureList
|
||||
import org.bouncycastle.openpgp.PGPSignatureList
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation
|
||||
import org.bouncycastle.util.io.Streams
|
||||
import org.pgpainless.decryption_verification.OpenPgpInputStream
|
||||
import org.pgpainless.decryption_verification.cleartext_signatures.ClearsignedMessageUtil
|
||||
import org.pgpainless.exception.WrongConsumingMethodException
|
||||
import org.pgpainless.implementation.ImplementationFactory
|
||||
import org.pgpainless.util.ArmoredOutputStreamFactory
|
||||
import sop.ReadyWithResult
|
||||
import sop.Signatures
|
||||
|
@ -72,8 +72,7 @@ class InlineDetachImpl : InlineDetach {
|
|||
}
|
||||
|
||||
// handle binary OpenPGP data
|
||||
var objectFactory =
|
||||
ImplementationFactory.getInstance().getPGPObjectFactory(pgpIn)
|
||||
var objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(pgpIn)
|
||||
var next: Any?
|
||||
|
||||
while (objectFactory.nextObject().also { next = it } != null) {
|
||||
|
@ -95,8 +94,8 @@ class InlineDetachImpl : InlineDetach {
|
|||
// Decompress compressed data
|
||||
try {
|
||||
objectFactory =
|
||||
ImplementationFactory.getInstance()
|
||||
.getPGPObjectFactory((next as PGPCompressedData).dataStream)
|
||||
OpenPGPImplementation.getInstance()
|
||||
.pgpObjectFactory((next as PGPCompressedData).dataStream)
|
||||
} catch (e: PGPException) {
|
||||
throw SOPGPException.BadData(
|
||||
"Cannot decompress PGPCompressedData", e)
|
||||
|
|
|
@ -6,6 +6,7 @@ package org.pgpainless.sop
|
|||
|
||||
import org.bouncycastle.bcpg.KeyIdentifier
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.bouncycastle.openpgp.PGPSecretKey
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
|
@ -82,8 +83,8 @@ class MatchMakingSecretKeyRingProtector : SecretKeyRingProtector {
|
|||
override fun getDecryptor(keyIdentifier: KeyIdentifier): PBESecretKeyDecryptor? =
|
||||
protector.getDecryptor(keyIdentifier)
|
||||
|
||||
override fun getEncryptor(keyIdentifier: KeyIdentifier): PBESecretKeyEncryptor? =
|
||||
protector.getEncryptor(keyIdentifier)
|
||||
override fun getEncryptor(key: PGPPublicKey): PBESecretKeyEncryptor? =
|
||||
protector.getEncryptor(key)
|
||||
|
||||
override fun getKeyPassword(p0: OpenPGPKey.OpenPGPSecretKey): CharArray? =
|
||||
protector.getKeyPassword(p0)
|
||||
|
|
|
@ -22,10 +22,10 @@ import org.bouncycastle.openpgp.PGPObjectFactory;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
|
@ -153,13 +153,13 @@ public class InlineDetachTest {
|
|||
|
||||
ByteArrayOutputStream literalDataAndSignatures = new ByteArrayOutputStream();
|
||||
ArmoredInputStream armorIn = new ArmoredInputStream(new ByteArrayInputStream(inlineSigned));
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(armorIn);
|
||||
PGPObjectFactory objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(armorIn);
|
||||
Object next;
|
||||
while ((next = objectFactory.nextObject()) != null) {
|
||||
if (next instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressedData = (PGPCompressedData) next;
|
||||
try {
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(compressedData.getDataStream());
|
||||
objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(compressedData.getDataStream());
|
||||
} catch (PGPException e) {
|
||||
throw new SOPGPException.BadData("Cannot decompress compressed data", e);
|
||||
}
|
||||
|
|
|
@ -96,13 +96,13 @@ public class MatchMakingSecretKeyRingProtectorTest {
|
|||
MatchMakingSecretKeyRingProtector protector = new MatchMakingSecretKeyRingProtector();
|
||||
protector.addSecretKey(unprotectedKey);
|
||||
assertTrue(protector.hasPassphraseFor(unprotectedKey.getPublicKey().getKeyID()));
|
||||
assertNull(protector.getEncryptor(unprotectedKey.getPublicKey().getKeyID()));
|
||||
assertNull(protector.getEncryptor(unprotectedKey.getPublicKey()));
|
||||
assertNull(protector.getDecryptor(unprotectedKey.getPublicKey().getKeyID()));
|
||||
|
||||
PGPSecretKeyRing protectedKey = PGPainless.readKeyRing().secretKeyRing(PROTECTED_KEY);
|
||||
protector.addSecretKey(protectedKey);
|
||||
protector.addPassphrase(Passphrase.fromPassword(PASSWORD));
|
||||
assertNotNull(protector.getEncryptor(protectedKey.getPublicKey().getKeyID()));
|
||||
assertNotNull(protector.getEncryptor(protectedKey.getPublicKey()));
|
||||
assertNotNull(protector.getDecryptor(protectedKey.getPublicKey().getKeyID()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue