1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-06 20:31:08 +01:00

Remove unused KeyRingSelectionStrategy implementations

This commit is contained in:
Paul Schaub 2025-03-25 13:03:52 +01:00
parent acbb93066e
commit 57b6795513
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
14 changed files with 0 additions and 666 deletions

View file

@ -1,88 +0,0 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util.selection.keyring;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.junit.jupiter.api.Test;
import org.pgpainless.key.TestKeys;
import org.pgpainless.util.MultiMap;
import org.pgpainless.util.selection.keyring.impl.ExactUserId;
public class KeyRingsFromCollectionTest {
@Test
public void selectSecretKeyRingFromSecretKeyRingCollectionTest() throws IOException, PGPException {
PGPSecretKeyRing emil = TestKeys.getEmilSecretKeyRing();
PGPSecretKeyRing juliet = TestKeys.getJulietSecretKeyRing();
PGPSecretKeyRingCollection collection = new PGPSecretKeyRingCollection(Arrays.asList(emil, juliet));
SecretKeyRingSelectionStrategy<String> strategy = new ExactUserId.SecRingSelectionStrategy();
Set<PGPSecretKeyRing> secretKeyRings = strategy.selectKeyRingsFromCollection(TestKeys.JULIET_UID, collection);
assertEquals(1, secretKeyRings.size());
assertEquals(juliet.getPublicKey().getKeyID(), secretKeyRings.iterator().next().getPublicKey().getKeyID());
}
@Test
public void selectSecretKeyRingMapFromSecretKeyRingCollectionMapTest() throws IOException, PGPException {
PGPSecretKeyRing emil = TestKeys.getEmilSecretKeyRing();
PGPSecretKeyRing juliet = TestKeys.getJulietSecretKeyRing();
MultiMap<String, PGPSecretKeyRingCollection> map = new MultiMap<>();
PGPSecretKeyRingCollection julietCollection = new PGPSecretKeyRingCollection(Arrays.asList(emil, juliet));
map.put(TestKeys.JULIET_UID, julietCollection);
PGPSecretKeyRingCollection emilCollection = new PGPSecretKeyRingCollection(Collections.singletonList(emil));
map.put(TestKeys.EMIL_UID, emilCollection);
assertEquals(2, julietCollection.size());
map.put("invalidId", emilCollection);
SecretKeyRingSelectionStrategy<String> strategy = new ExactUserId.SecRingSelectionStrategy();
MultiMap<String, PGPSecretKeyRing> selected = strategy.selectKeyRingsFromCollections(map);
assertEquals(1, selected.get(TestKeys.JULIET_UID).size());
assertEquals(1, selected.get(TestKeys.EMIL_UID).size());
assertTrue(selected.get("invalidId").isEmpty());
}
@Test
public void selectPublicKeyRingFromPublicKeyRingCollectionTest() throws IOException {
PGPPublicKeyRing emil = TestKeys.getEmilPublicKeyRing();
PGPPublicKeyRing juliet = TestKeys.getJulietPublicKeyRing();
PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(Arrays.asList(emil, juliet));
PublicKeyRingSelectionStrategy<String> strategy = new ExactUserId.PubRingSelectionStrategy();
Set<PGPPublicKeyRing> publicKeyRings = strategy.selectKeyRingsFromCollection(TestKeys.JULIET_UID, collection);
assertEquals(1, publicKeyRings.size());
assertEquals(juliet.getPublicKey().getKeyID(), publicKeyRings.iterator().next().getPublicKey().getKeyID());
}
@Test
public void selectPublicKeyRingMapFromPublicKeyRingCollectionMapTest() throws IOException {
PGPPublicKeyRing emil = TestKeys.getEmilPublicKeyRing();
PGPPublicKeyRing juliet = TestKeys.getJulietPublicKeyRing();
MultiMap<String, PGPPublicKeyRingCollection> map = new MultiMap<>();
PGPPublicKeyRingCollection julietCollection = new PGPPublicKeyRingCollection(Arrays.asList(emil, juliet));
map.plus(TestKeys.JULIET_UID, julietCollection);
PGPPublicKeyRingCollection emilCollection = new PGPPublicKeyRingCollection(Collections.singletonList(emil));
map.plus(TestKeys.EMIL_UID, emilCollection);
assertEquals(2, julietCollection.size());
map.plus("invalidId", emilCollection);
PublicKeyRingSelectionStrategy<String> strategy = new ExactUserId.PubRingSelectionStrategy();
MultiMap<String, PGPPublicKeyRing> selected = strategy.selectKeyRingsFromCollections(map);
assertEquals(1, selected.get(TestKeys.JULIET_UID).size());
assertEquals(1, selected.get(TestKeys.EMIL_UID).size());
assertTrue(selected.get("invalidId").isEmpty());
}
}

View file

@ -1,52 +0,0 @@
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util.selection.keyring;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.Test;
import org.pgpainless.key.TestKeys;
import org.pgpainless.util.selection.keyring.impl.Whitelist;
public class WhitelistKeyRingSelectionStrategyTest {
@Test
public void testWithPublicKeys() throws IOException {
Map<String, Set<Long>> ids = new ConcurrentHashMap<>();
ids.put(TestKeys.JULIET_UID, Collections.singleton(TestKeys.JULIET_KEY_ID));
Whitelist.PubRingSelectionStrategy<String> selectionStrategy = new Whitelist.PubRingSelectionStrategy<>(ids);
PGPPublicKeyRing julietsKeys = TestKeys.getJulietPublicKeyRing();
PGPPublicKeyRing romeosKeys = TestKeys.getRomeoPublicKeyRing();
assertTrue(selectionStrategy.accept(TestKeys.JULIET_UID, julietsKeys));
assertFalse(selectionStrategy.accept(TestKeys.JULIET_UID, romeosKeys));
assertFalse(selectionStrategy.accept(TestKeys.ROMEO_UID, julietsKeys));
}
@Test
public void testWithSecretKeys() throws IOException, PGPException {
Map<String, Set<Long>> ids = new ConcurrentHashMap<>();
ids.put(TestKeys.JULIET_UID, Collections.singleton(TestKeys.JULIET_KEY_ID));
Whitelist.SecRingSelectionStrategy<String> selectionStrategy = new Whitelist.SecRingSelectionStrategy<>(ids);
PGPSecretKeyRing julietsKeys = TestKeys.getJulietSecretKeyRing();
PGPSecretKeyRing romeosKeys = TestKeys.getRomeoSecretKeyRing();
assertTrue(selectionStrategy.accept(TestKeys.JULIET_UID, julietsKeys));
assertFalse(selectionStrategy.accept(TestKeys.JULIET_UID, romeosKeys));
assertFalse(selectionStrategy.accept(TestKeys.ROMEO_UID, julietsKeys));
}
}

View file

@ -1,57 +0,0 @@
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util.selection.keyring;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.Test;
import org.pgpainless.key.TestKeys;
import org.pgpainless.util.selection.keyring.impl.Wildcard;
public class WildcardKeyRingSelectionStrategyTest {
private static final Wildcard.PubRingSelectionStrategy<String> pubKeySelectionStrategy
= new Wildcard.PubRingSelectionStrategy<>();
private static final Wildcard.SecRingSelectionStrategy<String> secKeySelectionStrategy
= new Wildcard.SecRingSelectionStrategy<>();
@Test
public void testStratAcceptsMatchingUIDsOnPubKey() throws IOException {
String uid = TestKeys.EMIL_UID;
PGPPublicKeyRing key = TestKeys.getEmilPublicKeyRing();
assertTrue(pubKeySelectionStrategy.accept(uid, key));
}
@Test
public void testStratAcceptsMismatchingUIDsOnPubKey() throws IOException {
String uid = "blabla@bla.bla";
PGPPublicKeyRing key = TestKeys.getEmilPublicKeyRing();
assertTrue(pubKeySelectionStrategy.accept(uid, key));
}
@Test
public void testStratAcceptsMatchingUIDsOnSecKey() throws IOException, PGPException {
String uid = TestKeys.EMIL_UID;
PGPSecretKeyRing key = TestKeys.getEmilSecretKeyRing();
assertTrue(secKeySelectionStrategy.accept(uid, key));
}
@Test
public void testStratAcceptsMismatchingUIDsOnSecKey() throws IOException, PGPException {
String uid = "blabla@bla.bla";
PGPSecretKeyRing key = TestKeys.getEmilSecretKeyRing();
assertTrue(secKeySelectionStrategy.accept(uid, key));
}
}

View file

@ -1,72 +0,0 @@
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util.selection.keyring;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.Test;
import org.pgpainless.key.TestKeys;
import org.pgpainless.util.selection.keyring.impl.XMPP;
public class XmppKeyRingSelectionStrategyTest {
private static final XMPP.PubRingSelectionStrategy pubKeySelectionStrategy =
new XMPP.PubRingSelectionStrategy();
private static final XMPP.SecRingSelectionStrategy secKeySelectionStrategy =
new XMPP.SecRingSelectionStrategy();
@Test
public void testMatchingXmppUIDAcceptedOnPubKey() throws IOException {
String uid = "xmpp:juliet@capulet.lit";
PGPPublicKeyRing key = TestKeys.getJulietPublicKeyRing();
assertTrue(pubKeySelectionStrategy.accept(uid, key));
}
@Test
public void testAddressIsFormattedToMatchOnPubKey() throws IOException {
String uid = "juliet@capulet.lit";
PGPPublicKeyRing key = TestKeys.getJulietPublicKeyRing();
assertTrue(pubKeySelectionStrategy.accept(uid, key));
}
@Test
public void testPubKeyWithDifferentUIDIsRejected() throws IOException {
String wrongUid = "romeo@montague.lit";
PGPPublicKeyRing key = TestKeys.getJulietPublicKeyRing();
assertFalse(pubKeySelectionStrategy.accept(wrongUid, key));
}
@Test
public void testMatchingEmailUIDAcceptedOnSecKey() throws IOException, PGPException {
String uid = "xmpp:juliet@capulet.lit";
PGPSecretKeyRing key = TestKeys.getJulietSecretKeyRing();
assertTrue(secKeySelectionStrategy.accept(uid, key));
}
@Test
public void testAddressIsFormattedToMatchOnSecKey() throws IOException, PGPException {
String uid = "juliet@capulet.lit";
PGPSecretKeyRing key = TestKeys.getJulietSecretKeyRing();
assertTrue(secKeySelectionStrategy.accept(uid, key));
}
@Test
public void testSecKeyWithDifferentUIDIsRejected() throws IOException, PGPException {
String wrongUid = "romeo@montague.lit";
PGPSecretKeyRing key = TestKeys.getJulietSecretKeyRing();
assertFalse(secKeySelectionStrategy.accept(wrongUid, key));
}
}