Skip to content

Commit 0716d02

Browse files
committed
Further integration of OpenPGPImplementation class
1 parent 69cadc1 commit 0716d02

File tree

4 files changed

+13
-57
lines changed

4 files changed

+13
-57
lines changed

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPCertificate.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
*/
6262
public class OpenPGPCertificate
6363
{
64-
private final PGPContentVerifierBuilderProvider contentVerifierBuilderProvider;
64+
private final OpenPGPImplementation implementation;
6565

6666
private final PGPKeyRing rawCert;
6767
private final OpenPGPPrimaryKey primaryKey;
@@ -76,21 +76,15 @@ public OpenPGPCertificate(PGPKeyRing rawCert)
7676
this(rawCert, new BcOpenPGPImplementation());
7777
}
7878

79-
public OpenPGPCertificate(PGPKeyRing rawCert, OpenPGPImplementation implementation)
80-
{
81-
this(rawCert, implementation.pgpContentVerifierBuilderProvider());
82-
}
83-
8479
/**
8580
* Instantiate an {@link OpenPGPCertificate} from a parsed {@link PGPPublicKeyRing}.
8681
*
8782
* @param rawCert public key ring
88-
* @param contentVerifierBuilderProvider provider for signature verifiers
83+
* @param implementation OpenPGP implementation
8984
*/
90-
public OpenPGPCertificate(PGPKeyRing rawCert,
91-
PGPContentVerifierBuilderProvider contentVerifierBuilderProvider)
85+
public OpenPGPCertificate(PGPKeyRing rawCert, OpenPGPImplementation implementation)
9286
{
93-
this.contentVerifierBuilderProvider = contentVerifierBuilderProvider;
87+
this.implementation = implementation;
9488

9589
this.rawCert = rawCert;
9690
this.subkeys = new HashMap<>();
@@ -459,7 +453,7 @@ private boolean isBoundBy(OpenPGPCertificateComponent component,
459453
}
460454

461455
// Chain needs to be valid (signatures correct)
462-
if (chain.isValid(contentVerifierBuilderProvider))
456+
if (chain.isValid(implementation.pgpContentVerifierBuilderProvider()))
463457
{
464458
// Chain needs to not contain a revocation signature, otherwise the component is considered revoked
465459
return !chain.isRevocation();
@@ -1727,7 +1721,7 @@ public boolean isEffectiveAt(Date evaluationDate)
17271721
public boolean isValid()
17281722
throws PGPSignatureException
17291723
{
1730-
return isValid(getRootKey().getCertificate().contentVerifierBuilderProvider);
1724+
return isValid(getRootKey().getCertificate().implementation.pgpContentVerifierBuilderProvider());
17311725
}
17321726

17331727
public boolean isValid(PGPContentVerifierBuilderProvider contentVerifierBuilderProvider)

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKey.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.bouncycastle.openpgp.PGPUtil;
1515
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
1616
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptorBuilderProvider;
17-
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
1817

1918
import java.io.ByteArrayInputStream;
2019
import java.io.ByteArrayOutputStream;
@@ -36,17 +35,7 @@ public OpenPGPKey(PGPSecretKeyRing rawKey)
3635

3736
public OpenPGPKey(PGPSecretKeyRing rawKey, OpenPGPImplementation implementation)
3837
{
39-
this(
40-
rawKey,
41-
implementation.pgpContentVerifierBuilderProvider(),
42-
implementation.pbeSecretKeyDecryptorBuilderProvider());
43-
}
44-
45-
public OpenPGPKey(PGPSecretKeyRing rawKey,
46-
PGPContentVerifierBuilderProvider contentVerifierBuilderProvider,
47-
PBESecretKeyDecryptorBuilderProvider decryptorBuilderProvider)
48-
{
49-
super(rawKey, contentVerifierBuilderProvider);
38+
super(rawKey, implementation);
5039

5140
this.secretKeys = new HashMap<>();
5241
for (OpenPGPComponentKey key : getKeys())
@@ -58,7 +47,7 @@ public OpenPGPKey(PGPSecretKeyRing rawKey,
5847
continue;
5948
}
6049

61-
secretKeys.put(identifier, new OpenPGPSecretKey(key, secretKey, decryptorBuilderProvider));
50+
secretKeys.put(identifier, new OpenPGPSecretKey(key, secretKey, implementation.pbeSecretKeyDecryptorBuilderProvider()));
6251
}
6352
}
6453

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPMessageGenerator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static class Recipient
601601
*/
602602
public Recipient(PGPPublicKeyRing certificate, SubkeySelector subkeySelector, OpenPGPImplementation implementation)
603603
{
604-
this(new OpenPGPCertificate(certificate, implementation.pgpContentVerifierBuilderProvider()), subkeySelector);
604+
this(new OpenPGPCertificate(certificate, implementation), subkeySelector);
605605
}
606606

607607
public Recipient(OpenPGPCertificate certificate, SubkeySelector subkeySelector)
@@ -653,9 +653,7 @@ public Signer(PGPSecretKeyRing signingKey,
653653
SubkeySelector subkeySelector,
654654
OpenPGPImplementation implementation)
655655
{
656-
this(new OpenPGPKey(signingKey,
657-
implementation.pgpContentVerifierBuilderProvider(),
658-
implementation.pbeSecretKeyDecryptorBuilderProvider()),
656+
this(new OpenPGPKey(signingKey, implementation),
659657
decryptorProvider, subkeySelector);
660658
}
661659

pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPCertificateTest.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
import org.bouncycastle.bcpg.test.AbstractPacketTest;
88
import org.bouncycastle.openpgp.KeyIdentifier;
99
import org.bouncycastle.openpgp.PGPObjectFactory;
10-
import org.bouncycastle.openpgp.PGPPublicKeyRing;
11-
import org.bouncycastle.openpgp.PGPSecretKeyRing;
1210
import org.bouncycastle.openpgp.PGPSignature;
1311
import org.bouncycastle.openpgp.PGPSignatureList;
12+
import org.bouncycastle.openpgp.api.BcOpenPGPImplementation;
1413
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
1514
import org.bouncycastle.openpgp.api.OpenPGPKey;
1615
import org.bouncycastle.openpgp.api.util.UTCUtil;
1716
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
18-
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilderProvider;
19-
import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
2017

2118
import java.io.ByteArrayInputStream;
2219
import java.io.IOException;
@@ -45,28 +42,6 @@ public void performTest()
4542
testPKSignsPKRevocationSuperseded();
4643
}
4744

48-
private OpenPGPCertificate readCertificate(String armored)
49-
throws IOException
50-
{
51-
ByteArrayInputStream bIn = new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8));
52-
ArmoredInputStream aIn = new ArmoredInputStream(bIn);
53-
BCPGInputStream pIn = new BCPGInputStream(aIn);
54-
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
55-
PGPPublicKeyRing publicKeys = (PGPPublicKeyRing) objFac.nextObject();
56-
return new OpenPGPCertificate(publicKeys, new BcPGPContentVerifierBuilderProvider());
57-
}
58-
59-
private OpenPGPKey readKey(String armored)
60-
throws IOException
61-
{
62-
ByteArrayInputStream bIn = new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8));
63-
ArmoredInputStream aIn = new ArmoredInputStream(bIn);
64-
BCPGInputStream pIn = new BCPGInputStream(aIn);
65-
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
66-
PGPSecretKeyRing secretKey = (PGPSecretKeyRing) objFac.nextObject();
67-
return new OpenPGPKey(secretKey, new BcPGPContentVerifierBuilderProvider(), new BcPBESecretKeyDecryptorBuilderProvider());
68-
}
69-
7045
private void testOpenPGPv6Key()
7146
throws IOException
7247
{
@@ -84,7 +59,7 @@ private void testOpenPGPv6Key()
8459
"M0g12vYxoWM8Y81W+bHBw805I8kWVkXU6vFOi+HWvv/ira7ofJu16NnoUkhclkUr\n" +
8560
"k0mXubZvyl4GBg==\n" +
8661
"-----END PGP PRIVATE KEY BLOCK-----";
87-
OpenPGPKey key = readKey(armoredKey);
62+
OpenPGPKey key = OpenPGPKey.fromAsciiArmor(armoredKey, new BcOpenPGPImplementation());
8863

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

@@ -803,7 +778,7 @@ private void testPKSignsPKRevocationSuperseded()
803778
private void signatureValidityTest(String cert, TestSignature... testSignatures)
804779
throws IOException
805780
{
806-
OpenPGPCertificate certificate = readCertificate(cert);
781+
OpenPGPCertificate certificate = OpenPGPCertificate.fromAsciiArmor(cert, new BcOpenPGPImplementation());
807782

808783
for (TestSignature test : testSignatures)
809784
{

0 commit comments

Comments
 (0)