diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ac003d..4d0b5547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ SPDX-License-Identifier: CC0-1.0 ## 1.0.0-rc9-SNAPSHOT - When key has both direct-key sig + primary user-id sig: resolve expiration date to earliest expiration +- Add `SecretKeyRingEditor.removeUserId()` convenience methods that do soft-revoke the user-id. +- Add `SelectUserId.byEmail()` which also matches the plain email address ## 1.0.0-rc8 - `KeyRingInfo.getPrimaryUserId()`: return first user-id when no primary user-id is found diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeUserIdsTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeUserIdsTest.java index e416bf04..a8c732b4 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeUserIdsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeUserIdsTest.java @@ -14,6 +14,7 @@ import java.util.NoSuchElementException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; +import org.bouncycastle.openpgp.PGPSignature; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; import org.pgpainless.key.info.KeyRingInfo; @@ -54,6 +55,37 @@ public class RevokeUserIdsTest { assertFalse(info.isUserIdValid("Alice ")); } + @Test + public void removeUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() + .modernKeyRing("Alice ", null); + SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); + + secretKeys = PGPainless.modifyKeyRing(secretKeys) + .addUserId("Allice ", protector) + .addUserId("Alice ", protector) + .done(); + + KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys); + assertTrue(info.isUserIdValid("Alice ")); + assertTrue(info.isUserIdValid("Allice ")); + assertTrue(info.isUserIdValid("Alice ")); + + secretKeys = PGPainless.modifyKeyRing(secretKeys) + .removeUserId("Allice ", protector) + .done(); + + info = PGPainless.inspectKeyRing(secretKeys); + assertTrue(info.isUserIdValid("Alice ")); + assertFalse(info.isUserIdValid("Allice ")); + assertTrue(info.isUserIdValid("Alice ")); + + PGPSignature revocation = info.getUserIdRevocation("Allice "); + + assertFalse(RevocationAttributes.Reason.isHardRevocation( + revocation.getHashedSubPackets().getRevocationReason().getRevocationReason())); + } + @Test public void emptySelectionYieldsNoSuchElementException() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()