1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-14 12:49:39 +02:00

Rename SubkeyLookup.getCertificateFingerprintsForSubkeyId()

This commit is contained in:
Paul Schaub 2022-03-01 14:36:22 +01:00
parent 5acd1f1812
commit 3193df37b0
8 changed files with 23 additions and 23 deletions

View file

@ -22,7 +22,7 @@ public class DatabaseSubkeyLookup implements SubkeyLookup {
}
@Override
public Set<String> getCertificatesForSubkeyId(long subkeyId) throws IOException {
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException {
try {
List<Entry> entries = dao.selectValues(subkeyId);
Set<String> certificates = new HashSet<>();

View file

@ -38,25 +38,25 @@ public class SqliteSubkeyLookupTest {
store("eb85bb5fa33a75e15e944e63f231550c4f47e38e", 123L, 234L);
store("d1a66e1a23b182c9980f788cfbfcc82a015e7330", 234L);
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificatesForSubkeyId(123L));
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(123L));
assertEquals(
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
lookup.getCertificatesForSubkeyId(234L));
lookup.getCertificateFingerprintsForSubkeyId(234L));
}
@Test
public void getNonExistingSubkeyYieldsNull() throws IOException {
assertTrue(lookup.getCertificatesForSubkeyId(6666666).isEmpty());
assertTrue(lookup.getCertificateFingerprintsForSubkeyId(6666666).isEmpty());
}
@Test
public void secondInstanceLookupTest() throws IOException, SQLException {
store("eb85bb5fa33a75e15e944e63f231550c4f47e38e", 1337L);
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificatesForSubkeyId(1337));
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(1337));
// do the lookup using a second db instance on the same file
DatabaseSubkeyLookup secondInstance = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificatesForSubkeyId(1337));
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificateFingerprintsForSubkeyId(1337));
}
@Test

View file

@ -18,7 +18,7 @@ public class InMemorySubkeyLookup implements SubkeyLookup {
private static final Map<Long, Set<String>> subkeyMap = new HashMap<>();
@Override
public Set<String> getCertificatesForSubkeyId(long subkeyId) {
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) {
Set<String> identifiers = subkeyMap.get(subkeyId);
if (identifiers == null) {
return Collections.emptySet();

View file

@ -56,26 +56,26 @@ public class SubkeyLookupTest {
public void testInsertGet(SubkeyLookup subject) throws IOException {
// Initially all null
assertTrue(subject.getCertificatesForSubkeyId(123).isEmpty());
assertTrue(subject.getCertificatesForSubkeyId(1337).isEmpty());
assertTrue(subject.getCertificatesForSubkeyId(420).isEmpty());
assertTrue(subject.getCertificateFingerprintsForSubkeyId(123).isEmpty());
assertTrue(subject.getCertificateFingerprintsForSubkeyId(1337).isEmpty());
assertTrue(subject.getCertificateFingerprintsForSubkeyId(420).isEmpty());
// Store one val, others still null
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(123L));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(123));
assertTrue(subject.getCertificatesForSubkeyId(1337).isEmpty());
assertTrue(subject.getCertificatesForSubkeyId(420).isEmpty());
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(123));
assertTrue(subject.getCertificateFingerprintsForSubkeyId(1337).isEmpty());
assertTrue(subject.getCertificateFingerprintsForSubkeyId(420).isEmpty());
// Store other val, first stays intact
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(1337L));
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(420L));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(123));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(1337));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(420));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(123));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(1337));
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(420));
// add additional entry for subkey
@ -83,6 +83,6 @@ public class SubkeyLookupTest {
assertEquals(
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
subject.getCertificatesForSubkeyId(123));
subject.getCertificateFingerprintsForSubkeyId(123));
}
}

View file

@ -20,7 +20,7 @@ public abstract class AbstractCertificateStore implements CertificateStore {
public Set<Certificate> getCertificatesBySubkeyId(long subkeyId)
throws IOException {
Set<String> identifiers = getCertificatesForSubkeyId(subkeyId);
Set<String> identifiers = getCertificateFingerprintsForSubkeyId(subkeyId);
if (identifiers.isEmpty()) {
return Collections.emptySet();
}

View file

@ -17,7 +17,7 @@ public interface SubkeyLookup {
* @param subkeyId subkey id
* @return fingerprint of the certificate
*/
Set<String> getCertificatesForSubkeyId(long subkeyId) throws IOException;
Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException;
/**
* Record, which certificate the subkey-ids in the list belong to.

View file

@ -112,8 +112,8 @@ public class SharedPGPCertificateDirectoryAdapter
}
@Override
public Set<String> getCertificatesForSubkeyId(long subkeyId) throws IOException {
return subkeyLookup.getCertificatesForSubkeyId(subkeyId);
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException {
return subkeyLookup.getCertificateFingerprintsForSubkeyId(subkeyId);
}
@Override

View file

@ -84,7 +84,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
Set<Long> subkeys = certificate.getSubkeyIds();
assertEquals(expectedSubkeys, subkeys);
for (long subkey : subkeys) {
assertEquals(Collections.singleton(fingerprint), store.getCertificatesForSubkeyId(subkey));
assertEquals(Collections.singleton(fingerprint), store.getCertificateFingerprintsForSubkeyId(subkey));
}
Certificate retrieved = store.getCertificate(fingerprint);
@ -108,7 +108,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
Set<Long> subkeys = certificate.getSubkeyIds();
assertEquals(3, subkeys.size());
for (long subkey : subkeys) {
assertEquals(Collections.singleton(fingerprint), store.getCertificatesForSubkeyId(subkey));
assertEquals(Collections.singleton(fingerprint), store.getCertificateFingerprintsForSubkeyId(subkey));
}
Certificate retrieved = store.getCertificate(fingerprint);