mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
SecretKeyRingEditor: Restructure arguments of modification methods
This commit is contained in:
parent
5e85e975cd
commit
151d3c7b96
6 changed files with 383 additions and 147 deletions
|
@ -39,7 +39,7 @@ public class KeyGenerationSubpacketsTest {
|
|||
|
||||
@Test
|
||||
public void verifyDefaultSubpacketsForUserIdSignatures()
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InterruptedException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
@ -87,6 +87,9 @@ public class KeyGenerationSubpacketsTest {
|
|||
|
||||
assertEquals("Bob", info.getPrimaryUserId());
|
||||
|
||||
// wait one sec so that it is clear that the new certification for alice is the most recent one
|
||||
Thread.sleep(1000);
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("Alice", new SelfSignatureSubpackets.Callback() {
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ package org.pgpainless.key.modification;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -16,6 +17,7 @@ import java.util.NoSuchElementException;
|
|||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.PGPainless;
|
||||
|
@ -25,6 +27,7 @@ import org.pgpainless.key.info.KeyRingInfo;
|
|||
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||
import org.pgpainless.key.util.UserId;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
public class AddUserIdTest {
|
||||
|
@ -109,4 +112,19 @@ public class AddUserIdTest {
|
|||
assertEquals("cheshirecat@wonderland.lit", userIds.next());
|
||||
assertFalse(userIds.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNewPrimaryUserIdTest() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice", null);
|
||||
UserId bob = UserId.newBuilder().withName("Bob").noEmail().noComment().build();
|
||||
|
||||
assertNotEquals("Bob", PGPainless.inspectKeyRing(secretKeys).getPrimaryUserId());
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addPrimaryUserId(bob, SecretKeyRingProtector.unprotectedKeys())
|
||||
.done();
|
||||
|
||||
assertEquals("Bob", PGPainless.inspectKeyRing(secretKeys).getPrimaryUserId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.junit.jupiter.api.Test;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.util.RevocationAttributes;
|
||||
import org.pgpainless.signature.subpackets.RevocationSignatureSubpackets;
|
||||
import org.pgpainless.util.selection.userid.SelectUserId;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
|
@ -39,7 +41,7 @@ public class RevokeUserIdsTest {
|
|||
assertTrue(info.isUserIdValid("Alice <alice@example.org>"));
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.revokeUserIds(SelectUserId.containsEmailAddress("alice@example.org"), protector, null)
|
||||
.revokeUserIds(SelectUserId.containsEmailAddress("alice@example.org"), protector, (RevocationSignatureSubpackets.Callback) null)
|
||||
.done();
|
||||
|
||||
info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
@ -57,6 +59,6 @@ public class RevokeUserIdsTest {
|
|||
PGPainless.modifyKeyRing(secretKeys).revokeUserIds(
|
||||
SelectUserId.containsEmailAddress("alice@example.org"),
|
||||
SecretKeyRingProtector.unprotectedKeys(),
|
||||
null));
|
||||
(RevocationAttributes) null));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue