1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

Port CanonicalizedDataEncryptionTest

This commit is contained in:
Paul Schaub 2025-02-18 14:13:55 +01:00
parent e3c586e182
commit 8936cf22d0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -22,11 +22,10 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPLiteralData; import org.bouncycastle.openpgp.PGPLiteralData;
import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
import org.bouncycastle.openpgp.PGPOnePassSignature; 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.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureGenerator; 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.openpgp.operator.bc.BcPGPContentSignerBuilder;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -109,13 +108,13 @@ public class CanonicalizedDataEncryptionTest {
String message = "Hello, World!\n"; String message = "Hello, World!\n";
private static PGPSecretKeyRing secretKeys; private static OpenPGPKey secretKeys;
private static PGPPublicKeyRing publicKeys; private static OpenPGPCertificate publicKeys;
@BeforeAll @BeforeAll
public static void readKeys() throws IOException { public static void readKeys() throws IOException {
secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); secretKeys = PGPainless.getInstance().readKey().parseKey(KEY);
publicKeys = PGPainless.extractCertificate(secretKeys); publicKeys = secretKeys.toCertificate();
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
System.out.println(PGPainless.asciiArmor(secretKeys)); System.out.println(PGPainless.asciiArmor(secretKeys));
// CHECKSTYLE:ON // CHECKSTYLE:ON
@ -397,7 +396,7 @@ public class CanonicalizedDataEncryptionTest {
public void manualSignAndVerify(DocumentSignatureType sigType, StreamEncoding streamEncoding) public void manualSignAndVerify(DocumentSignatureType sigType, StreamEncoding streamEncoding)
throws IOException, PGPException { throws IOException, PGPException {
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getSecretKey(), SecretKeyRingProtector.unprotectedKeys()); OpenPGPKey.OpenPGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKeys.getPrimarySecretKey(), SecretKeyRingProtector.unprotectedKeys());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armorOut = new ArmoredOutputStream(out); ArmoredOutputStream armorOut = new ArmoredOutputStream(out);
@ -406,9 +405,10 @@ public class CanonicalizedDataEncryptionTest {
PGPSignatureGenerator signer = new PGPSignatureGenerator( PGPSignatureGenerator signer = new PGPSignatureGenerator(
new BcPGPContentSignerBuilder( new BcPGPContentSignerBuilder(
secretKeys.getPublicKey().getAlgorithm(), secretKeys.getPrimaryKey().getPGPPublicKey().getAlgorithm(),
HashAlgorithm.SHA256.getAlgorithmId())); HashAlgorithm.SHA256.getAlgorithmId()),
signer.init(sigType.getSignatureType().getCode(), privateKey); secretKeys.getPrimaryKey().getPGPPublicKey());
signer.init(sigType.getSignatureType().getCode(), privateKey.getKeyPair().getPrivateKey());
PGPOnePassSignature ops = signer.generateOnePassVersion(false); PGPOnePassSignature ops = signer.generateOnePassVersion(false);
ops.encode(compressedOut); ops.encode(compressedOut);