Skip to content

Commit

Permalink
Default to BcOpenPGPImplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Nov 16, 2024
1 parent ecd7051 commit ea5cde9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public OpenPGPCertificate(PGPKeyRing rawCert, OpenPGPImplementation implementati
}
}

public static OpenPGPCertificate fromAsciiArmor(String armor)
throws IOException
{
return fromAsciiArmor(armor, new BcOpenPGPImplementation());
}

public static OpenPGPCertificate fromAsciiArmor(
String armor,
Expand Down
6 changes: 6 additions & 0 deletions pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public OpenPGPKey(PGPSecretKeyRing rawKey, OpenPGPImplementation implementation)
}
}

public static OpenPGPKey fromAsciiArmor(String armor)
throws IOException
{
return fromAsciiArmor(armor, new BcOpenPGPImplementation());
}

public static OpenPGPKey fromAsciiArmor(
String armor,
OpenPGPImplementation implementation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bouncycastle.openpgp.PGPObjectFactory;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.api.BcOpenPGPImplementation;
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
import org.bouncycastle.openpgp.api.OpenPGPKey;
import org.bouncycastle.openpgp.api.util.UTCUtil;
Expand Down Expand Up @@ -59,7 +58,7 @@ private void testOpenPGPv6Key()
"M0g12vYxoWM8Y81W+bHBw805I8kWVkXU6vFOi+HWvv/ira7ofJu16NnoUkhclkUr\n" +
"k0mXubZvyl4GBg==\n" +
"-----END PGP PRIVATE KEY BLOCK-----";
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(armoredKey, new BcOpenPGPImplementation());
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(armoredKey);

isTrue("Test key has no identities", key.getIdentities().isEmpty());

Expand Down Expand Up @@ -778,7 +777,7 @@ private void testPKSignsPKRevocationSuperseded()
private void signatureValidityTest(String cert, TestSignature... testSignatures)
throws IOException
{
OpenPGPCertificate certificate = OpenPGPCertificate.fromAsciiArmor(cert, new BcOpenPGPImplementation());
OpenPGPCertificate certificate = OpenPGPCertificate.fromAsciiArmor(cert);

for (TestSignature test : testSignatures)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
import org.bouncycastle.bcpg.test.AbstractPacketTest;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.api.BcOpenPGPImplementation;
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
import org.bouncycastle.openpgp.api.OpenPGPKey;
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
Expand Down Expand Up @@ -133,7 +132,7 @@ private void seipd2EncryptedMessage()
"j+VjFM21J0hqWlEg+bdiojWnKfA5AQpWUWtnNwDEM0g12vYxoWM8Y81W+bHBw805\n" +
"I8kWVkXU6vFOi+HWvv/ira7ofJu16NnoUkhclkUrk0mXubZvyl4GBg==\n" +
"-----END PGP PUBLIC KEY BLOCK-----";
OpenPGPCertificate cert = OpenPGPCertificate.fromAsciiArmor(v6Cert, new BcOpenPGPImplementation());
OpenPGPCertificate cert = OpenPGPCertificate.fromAsciiArmor(v6Cert);

OpenPGPMessageGenerator gen = new OpenPGPMessageGenerator();
gen.addEncryptionCertificate(cert);
Expand Down Expand Up @@ -231,7 +230,7 @@ private void seipd1EncryptedMessage()
"xqAY9Bwizt4FWgXuLm1a4+So4V9j1TRCXd12Uc2l2RNmgDE=\n" +
"=miES\n" +
"-----END PGP PRIVATE KEY BLOCK-----\n";
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(v4Key, new BcOpenPGPImplementation());
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(v4Key);

OpenPGPMessageGenerator gen = new OpenPGPMessageGenerator();
gen.addEncryptionCertificate(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.bcpg.test.AbstractPacketTest;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.api.BcOpenPGPImplementation;
import org.bouncycastle.openpgp.api.OpenPGPKey;
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
import org.bouncycastle.openpgp.api.OpenPGPMessageProcessor;
Expand Down Expand Up @@ -151,8 +150,7 @@ private void roundTripCompressedSymEncMessageMessage()
private void roundTripV6KeyEncryptedMessage()
throws IOException, PGPException
{
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(v6Key,
new BcOpenPGPImplementation());
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(v6Key);

OpenPGPMessageGenerator gen = new OpenPGPMessageGenerator()
.setArmored(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.api.BcOpenPGPImplementation;
import org.bouncycastle.openpgp.api.OpenPGPKey;
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
Expand Down Expand Up @@ -59,7 +58,7 @@ public void performTest()
private void staticEncryptedMessage()
throws IOException, PGPException
{
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(V6KEY, new BcOpenPGPImplementation());
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(V6KEY);

OpenPGPMessageGenerator gen = getStaticGenerator()
.addEncryptionCertificate(key);
Expand All @@ -75,7 +74,7 @@ private void staticEncryptedMessage()
private void staticSignedMessage()
throws IOException, PGPException
{
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(V6KEY, new BcOpenPGPImplementation());
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(V6KEY);
OpenPGPMessageGenerator gen = getStaticGenerator()
.addSigningKey(key, null);

Expand Down

0 comments on commit ea5cde9

Please sign in to comment.