mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 10:19:39 +02:00
Port PGPPublicKeyRingTest
This commit is contained in:
parent
1e67447efd
commit
69b0b2d371
1 changed files with 12 additions and 18 deletions
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package org.bouncycastle;
|
package org.bouncycastle;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -12,15 +11,16 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
|
||||||
import org.pgpainless.util.CollectionUtils;
|
import org.pgpainless.util.CollectionUtils;
|
||||||
|
|
||||||
public class PGPPublicKeyRingTest {
|
public class PGPPublicKeyRingTest {
|
||||||
|
|
||||||
|
private final PGPainless api = PGPainless.getInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Learning test to see if BC also makes userids available on subkeys.
|
* Learning test to see if BC also makes userids available on subkeys.
|
||||||
* It does not.
|
* It does not.
|
||||||
|
@ -29,15 +29,10 @@ public class PGPPublicKeyRingTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void subkeysDoNotHaveUserIDsTest() {
|
public void subkeysDoNotHaveUserIDsTest() {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("primary@user.id")
|
OpenPGPKey key = api.generateKey().simpleEcKeyRing("primary@user.id");
|
||||||
.getPGPSecretKeyRing();
|
OpenPGPCertificate certificate = key.toCertificate();
|
||||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
for (OpenPGPCertificate.OpenPGPComponentKey subkey : certificate.getSubkeys().values()) {
|
||||||
PGPPublicKey primaryKey = publicKeys.getPublicKey();
|
Iterator<String> userIds = subkey.getPGPPublicKey().getUserIDs();
|
||||||
for (PGPPublicKey subkey : publicKeys) {
|
|
||||||
Iterator<String> userIds = subkey.getUserIDs();
|
|
||||||
if (primaryKey == subkey) {
|
|
||||||
assertEquals("primary@user.id", userIds.next());
|
|
||||||
}
|
|
||||||
assertFalse(userIds.hasNext());
|
assertFalse(userIds.hasNext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,14 +40,13 @@ public class PGPPublicKeyRingTest {
|
||||||
@Test
|
@Test
|
||||||
public void removeUserIdTest() {
|
public void removeUserIdTest() {
|
||||||
String userId = "alice@wonderland.lit";
|
String userId = "alice@wonderland.lit";
|
||||||
PGPSecretKeyRing secretKeyRing = PGPainless.generateKeyRing().simpleEcKeyRing(userId)
|
OpenPGPKey key = api.generateKey().simpleEcKeyRing(userId);
|
||||||
.getPGPSecretKeyRing();
|
OpenPGPCertificate certificate = key.toCertificate();
|
||||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeyRing);
|
PGPPublicKey publicKey = certificate.getPrimaryKey().getPGPPublicKey();
|
||||||
|
|
||||||
List<String> userIds = CollectionUtils.iteratorToList(publicKeys.getPublicKey().getUserIDs());
|
List<String> userIds = CollectionUtils.iteratorToList(publicKey.getUserIDs());
|
||||||
assertTrue(userIds.contains(userId));
|
assertTrue(userIds.contains(userId));
|
||||||
|
|
||||||
PGPPublicKey publicKey = publicKeys.getPublicKey();
|
|
||||||
publicKey = PGPPublicKey.removeCertification(publicKey, userId);
|
publicKey = PGPPublicKey.removeCertification(publicKey, userId);
|
||||||
|
|
||||||
userIds = CollectionUtils.iteratorToList(publicKey.getUserIDs());
|
userIds = CollectionUtils.iteratorToList(publicKey.getUserIDs());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue