mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-13 12:19:38 +02:00
Restructured API
This commit is contained in:
parent
b8a376f86a
commit
3438b7259a
6 changed files with 97 additions and 58 deletions
|
@ -5,12 +5,15 @@
|
|||
package org.pgpainless.signature.builder;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.bcpg.sig.NotationData;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
|
@ -22,6 +25,8 @@ import org.pgpainless.algorithm.EncryptionPurpose;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
public class SubkeyBindingSignatureBuilderTest {
|
||||
|
@ -36,20 +41,35 @@ public class SubkeyBindingSignatureBuilderTest {
|
|||
|
||||
PGPSecretKeyRing tempSubkeyRing = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Subkeys", null);
|
||||
PGPPublicKey subkey = PGPainless.inspectKeyRing(tempSubkeyRing)
|
||||
PGPPublicKey subkeyPub = PGPainless.inspectKeyRing(tempSubkeyRing)
|
||||
.getEncryptionSubkeys(EncryptionPurpose.ANY).get(0);
|
||||
PGPSecretKey subkeySec = tempSubkeyRing.getSecretKey(subkeyPub.getKeyID());
|
||||
|
||||
SubkeyBindingSignatureBuilder skbb = new SubkeyBindingSignatureBuilder(secretKey.getSecretKey(), protector);
|
||||
skbb.getHashedSubpackets().addNotationData(false, "testnotation@pgpainless.org", "hello-world");
|
||||
skbb.getHashedSubpackets().setKeyFlags(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE);
|
||||
PGPSignature binding = skbb.build(subkey);
|
||||
subkey = PGPPublicKey.addCertification(subkey, binding);
|
||||
PGPSecretKey secSubkey = tempSubkeyRing.getSecretKey(subkey.getKeyID());
|
||||
secSubkey = PGPSecretKey.replacePublicKey(secSubkey, subkey);
|
||||
secretKey = PGPSecretKeyRing.insertSecretKey(secretKey, secSubkey);
|
||||
PGPSignature binding = SignatureBuilder.bindNonSigningSubkey(
|
||||
secretKey.getSecretKey(), protector,
|
||||
new SelfSignatureSubpackets.Callback() {
|
||||
@Override
|
||||
public void modifyHashedSubpackets(SelfSignatureSubpackets subpackets) {
|
||||
subpackets.addNotationData(false, "testnotation@pgpainless.org", "hello-world");
|
||||
}
|
||||
}, KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE)
|
||||
.build(subkeyPub);
|
||||
|
||||
subkeyPub = PGPPublicKey.addCertification(subkeyPub, binding);
|
||||
subkeySec = PGPSecretKey.replacePublicKey(subkeySec, subkeyPub);
|
||||
secretKey = PGPSecretKeyRing.insertSecretKey(secretKey, subkeySec);
|
||||
|
||||
info = PGPainless.inspectKeyRing(secretKey);
|
||||
List<PGPPublicKey> nextSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.ANY);
|
||||
assertEquals(previousSubkeys.size() + 1, nextSubkeys.size());
|
||||
subkeyPub = secretKey.getPublicKey(subkeyPub.getKeyID());
|
||||
Iterator<PGPSignature> newBindingSigs = subkeyPub.getSignaturesForKeyID(secretKey.getPublicKey().getKeyID());
|
||||
PGPSignature bindingSig = newBindingSigs.next();
|
||||
assertNotNull(bindingSig);
|
||||
List<NotationData> notations = SignatureSubpacketsUtil.getHashedNotationData(bindingSig);
|
||||
|
||||
assertEquals(1, notations.size());
|
||||
assertEquals("testnotation@pgpainless.org", notations.get(0).getNotationName());
|
||||
assertEquals("hello-world", notations.get(0).getNotationValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue