mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-06 12:21:15 +01:00
Pass down API instance
This commit is contained in:
parent
d24a4a0883
commit
12ff104cf8
17 changed files with 157 additions and 112 deletions
|
|
@ -33,7 +33,8 @@ public class SubkeyAndPrimaryKeyBindingSignatureTest {
|
|||
|
||||
@Test
|
||||
public void testRebindSubkey() throws PGPException, IOException {
|
||||
OpenPGPKey secretKeys = PGPainless.getInstance().toKey(TestKeys.getEmilSecretKeyRing());
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey secretKeys = api.toKey(TestKeys.getEmilSecretKeyRing());
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
||||
OpenPGPKey.OpenPGPSecretKey primaryKey = secretKeys.getPrimarySecretKey();
|
||||
|
|
@ -47,7 +48,7 @@ public class SubkeyAndPrimaryKeyBindingSignatureTest {
|
|||
HashAlgorithm.SHA512, HashAlgorithm.SHA384, HashAlgorithm.SHA256, HashAlgorithm.SHA224)),
|
||||
hashAlgorithmSet);
|
||||
|
||||
SubkeyBindingSignatureBuilder sbb = new SubkeyBindingSignatureBuilder(primaryKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
SubkeyBindingSignatureBuilder sbb = new SubkeyBindingSignatureBuilder(primaryKey, SecretKeyRingProtector.unprotectedKeys(), api);
|
||||
sbb.applyCallback(new SelfSignatureSubpackets.Callback() {
|
||||
@Override
|
||||
public void modifyHashedSubpackets(SelfSignatureSubpackets hashedSubpackets) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import org.bouncycastle.bcpg.sig.Exportable;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPSignature;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -30,17 +29,20 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
|
||||
@Test
|
||||
public void testInvalidSignatureTypeThrows() {
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new ThirdPartyCertificationSignatureBuilder(
|
||||
SignatureType.BINARY_DOCUMENT, // invalid type
|
||||
secretKeys.getPrimarySecretKey(),
|
||||
SecretKeyRingProtector.unprotectedKeys()));
|
||||
SecretKeyRingProtector.unprotectedKeys(),
|
||||
api));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserIdCertification() throws PGPException {
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
|
||||
|
|
@ -49,7 +51,8 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
|
||||
ThirdPartyCertificationSignatureBuilder signatureBuilder = new ThirdPartyCertificationSignatureBuilder(
|
||||
secretKeys.getPrimarySecretKey(),
|
||||
SecretKeyRingProtector.unprotectedKeys());
|
||||
SecretKeyRingProtector.unprotectedKeys(),
|
||||
api);
|
||||
|
||||
signatureBuilder.applyCallback(new CertificationSubpackets.Callback() {
|
||||
@Override
|
||||
|
|
@ -70,7 +73,7 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
assertFalse(exportable.isExportable());
|
||||
|
||||
// test sig correctness
|
||||
signature.init(OpenPGPImplementation.getInstance().pgpContentVerifierBuilderProvider(),
|
||||
signature.init(api.getImplementation().pgpContentVerifierBuilderProvider(),
|
||||
secretKeys.getPrimaryKey().getPGPPublicKey());
|
||||
assertTrue(signature.verifyCertification("Bob", bobsPublicKeys.getPrimaryKey().getPGPPublicKey()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,14 @@ public class ThirdPartyDirectKeySignatureBuilderTest {
|
|||
|
||||
@Test
|
||||
public void testDirectKeySignatureBuilding() throws PGPException {
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
|
||||
DirectKeySelfSignatureBuilder dsb = new DirectKeySelfSignatureBuilder(
|
||||
secretKeys.getPrimarySecretKey(),
|
||||
SecretKeyRingProtector.unprotectedKeys());
|
||||
SecretKeyRingProtector.unprotectedKeys(),
|
||||
api);
|
||||
|
||||
Date now = new Date();
|
||||
Date t1 = new Date(now.getTime() + 1000 * 60 * 60);
|
||||
|
|
|
|||
|
|
@ -62,10 +62,11 @@ public class UniversalSignatureBuilderTest {
|
|||
|
||||
@Test
|
||||
public void createPetNameSignature() throws PGPException {
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey.OpenPGPSecretKey signingKey = secretKeys.getPrimarySecretKey();
|
||||
PGPSignature archetype = signingKey.getPublicKey().getPGPPublicKey().getSignatures().next();
|
||||
UniversalSignatureBuilder builder = new UniversalSignatureBuilder(
|
||||
signingKey, protector, archetype);
|
||||
signingKey, protector, archetype, api);
|
||||
|
||||
builder.applyCallback(new SignatureSubpackets.Callback() {
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue