mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-14 12:49:39 +02:00
Remove KeyRingUtils.deleteUserId() in favor of revoking SecretKeyRingEditor.removeUserId() methods
This commit is contained in:
parent
3a69f90401
commit
245376d7d0
4 changed files with 30 additions and 92 deletions
|
@ -6,17 +6,14 @@ package org.pgpainless.key.util;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bouncycastle.bcpg.attr.ImageAttribute;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
|
@ -33,49 +30,6 @@ import org.pgpainless.util.CollectionUtils;
|
|||
|
||||
public class KeyRingUtilTest {
|
||||
|
||||
@Test
|
||||
public void testDeleteUserIdFromSecretKeyRing()
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice", null);
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("Bob", SecretKeyRingProtector.unprotectedKeys())
|
||||
.done();
|
||||
assertEquals(2, CollectionUtils.iteratorToList(secretKeys.getPublicKey().getUserIDs()).size());
|
||||
|
||||
secretKeys = KeyRingUtils.deleteUserId(secretKeys, "Bob");
|
||||
|
||||
assertEquals(1, CollectionUtils.iteratorToList(secretKeys.getPublicKey().getUserIDs()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteUserIdFromPublicKeyRing()
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice", null);
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("Bob", SecretKeyRingProtector.unprotectedKeys())
|
||||
.done();
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
assertEquals(2, CollectionUtils.iteratorToList(publicKeys.getPublicKey().getUserIDs()).size());
|
||||
|
||||
publicKeys = KeyRingUtils.deleteUserId(publicKeys, "Alice");
|
||||
|
||||
assertEquals(1, CollectionUtils.iteratorToList(publicKeys.getPublicKey().getUserIDs()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteNonexistentUserIdFromKeyRingThrows()
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice", null);
|
||||
|
||||
assertThrows(NoSuchElementException.class,
|
||||
() -> KeyRingUtils.deleteUserId(secretKeys, "Charlie"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjectCertification() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue