mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Source PGPObjectFactory from ImplementationProvider
This commit is contained in:
parent
1681f3934f
commit
60f7a9d9ec
5 changed files with 51 additions and 11 deletions
|
@ -12,8 +12,7 @@ import java.io.IOException;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
|
@ -30,17 +29,21 @@ public class ImportExportKeyTest {
|
|||
ImplementationFactory.setFactoryImplementation(implementationFactory);
|
||||
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
|
||||
|
||||
BcKeyFingerprintCalculator calc = new BcKeyFingerprintCalculator();
|
||||
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
byte[] bytes = publicKeys.getEncoded();
|
||||
PGPPublicKeyRing parsed = new PGPPublicKeyRing(bytes, calc);
|
||||
assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExportImportSecretKeyRing() throws IOException, PGPException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
|
||||
public void testExportImportSecretKeyRing(ImplementationFactory implementationFactory) throws IOException, PGPException {
|
||||
ImplementationFactory.setFactoryImplementation(implementationFactory);
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing();
|
||||
|
||||
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
byte[] bytes = secretKeys.getEncoded();
|
||||
PGPSecretKeyRing parsed = new PGPSecretKeyRing(bytes, new BcKeyFingerprintCalculator());
|
||||
PGPSecretKeyRing parsed = new PGPSecretKeyRing(bytes, calc);
|
||||
assertArrayEquals(secretKeys.getEncoded(), parsed.getEncoded());
|
||||
assertEquals(secretKeys.getPublicKey().getKeyID(), parsed.getPublicKey().getKeyID());
|
||||
}
|
||||
|
|
|
@ -23,11 +23,13 @@ import org.bouncycastle.openpgp.PGPLiteralData;
|
|||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
|
||||
public class ArmorUtilsTest {
|
||||
|
@ -142,8 +144,10 @@ public class ArmorUtilsTest {
|
|||
"-----END PGP MESSAGE-----\n", out.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeExampleTest() throws IOException, PGPException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
|
||||
public void decodeExampleTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
|
||||
ImplementationFactory.setFactoryImplementation(implementationFactory);
|
||||
String armored = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"Version: OpenPrivacy 0.99\n" +
|
||||
"\n" +
|
||||
|
@ -152,9 +156,10 @@ public class ArmorUtilsTest {
|
|||
"=njUN\n" +
|
||||
"-----END PGP MESSAGE-----";
|
||||
InputStream inputStream = PGPUtil.getDecoderStream(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
|
||||
PGPObjectFactory factory = new BcPGPObjectFactory(inputStream);
|
||||
|
||||
PGPObjectFactory factory = ImplementationFactory.getInstance().getPGPObjectFactory(inputStream);
|
||||
PGPCompressedData compressed = (PGPCompressedData) factory.nextObject();
|
||||
factory = new BcPGPObjectFactory(compressed.getDataStream());
|
||||
factory = ImplementationFactory.getInstance().getPGPObjectFactory(compressed.getDataStream());
|
||||
PGPLiteralData literal = (PGPLiteralData) factory.nextObject();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
assertEquals("_CONSOLE", literal.getFileName());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue