From 8936cf22d02502f6565880c73691a68cf7f0851e Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 18 Feb 2025 14:13:55 +0100 Subject: [PATCH] Port CanonicalizedDataEncryptionTest --- .../CanonicalizedDataEncryptionTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/CanonicalizedDataEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/CanonicalizedDataEncryptionTest.java index f9936db0..d59edcaf 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/CanonicalizedDataEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/CanonicalizedDataEncryptionTest.java @@ -22,11 +22,10 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPLiteralData; import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPOnePassSignature; -import org.bouncycastle.openpgp.PGPPrivateKey; -import org.bouncycastle.openpgp.PGPPublicKeyRing; -import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureGenerator; +import org.bouncycastle.openpgp.api.OpenPGPCertificate; +import org.bouncycastle.openpgp.api.OpenPGPKey; import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.BeforeAll; @@ -109,13 +108,13 @@ public class CanonicalizedDataEncryptionTest { String message = "Hello, World!\n"; - private static PGPSecretKeyRing secretKeys; - private static PGPPublicKeyRing publicKeys; + private static OpenPGPKey secretKeys; + private static OpenPGPCertificate publicKeys; @BeforeAll public static void readKeys() throws IOException { - secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); - publicKeys = PGPainless.extractCertificate(secretKeys); + secretKeys = PGPainless.getInstance().readKey().parseKey(KEY); + publicKeys = secretKeys.toCertificate(); // CHECKSTYLE:OFF System.out.println(PGPainless.asciiArmor(secretKeys)); // CHECKSTYLE:ON @@ -397,7 +396,7 @@ public class CanonicalizedDataEncryptionTest { public void manualSignAndVerify(DocumentSignatureType sigType, StreamEncoding streamEncoding) throws IOException, PGPException { - PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getSecretKey(), SecretKeyRingProtector.unprotectedKeys()); + OpenPGPKey.OpenPGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getPrimarySecretKey(), SecretKeyRingProtector.unprotectedKeys()); ByteArrayOutputStream out = new ByteArrayOutputStream(); ArmoredOutputStream armorOut = new ArmoredOutputStream(out); @@ -406,9 +405,10 @@ public class CanonicalizedDataEncryptionTest { PGPSignatureGenerator signer = new PGPSignatureGenerator( new BcPGPContentSignerBuilder( - secretKeys.getPublicKey().getAlgorithm(), - HashAlgorithm.SHA256.getAlgorithmId())); - signer.init(sigType.getSignatureType().getCode(), privateKey); + secretKeys.getPrimaryKey().getPGPPublicKey().getAlgorithm(), + HashAlgorithm.SHA256.getAlgorithmId()), + secretKeys.getPrimaryKey().getPGPPublicKey()); + signer.init(sigType.getSignatureType().getCode(), privateKey.getKeyPair().getPrivateKey()); PGPOnePassSignature ops = signer.generateOnePassVersion(false); ops.encode(compressedOut);