mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-15 05:09:38 +02:00
Rename SubkeyLookup.getCertificateFingerprintsForSubkeyId()
This commit is contained in:
parent
5acd1f1812
commit
3193df37b0
8 changed files with 23 additions and 23 deletions
|
@ -22,7 +22,7 @@ public class DatabaseSubkeyLookup implements SubkeyLookup {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getCertificatesForSubkeyId(long subkeyId) throws IOException {
|
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException {
|
||||||
try {
|
try {
|
||||||
List<Entry> entries = dao.selectValues(subkeyId);
|
List<Entry> entries = dao.selectValues(subkeyId);
|
||||||
Set<String> certificates = new HashSet<>();
|
Set<String> certificates = new HashSet<>();
|
||||||
|
|
|
@ -38,25 +38,25 @@ public class SqliteSubkeyLookupTest {
|
||||||
store("eb85bb5fa33a75e15e944e63f231550c4f47e38e", 123L, 234L);
|
store("eb85bb5fa33a75e15e944e63f231550c4f47e38e", 123L, 234L);
|
||||||
store("d1a66e1a23b182c9980f788cfbfcc82a015e7330", 234L);
|
store("d1a66e1a23b182c9980f788cfbfcc82a015e7330", 234L);
|
||||||
|
|
||||||
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificatesForSubkeyId(123L));
|
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(123L));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
|
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
|
||||||
lookup.getCertificatesForSubkeyId(234L));
|
lookup.getCertificateFingerprintsForSubkeyId(234L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNonExistingSubkeyYieldsNull() throws IOException {
|
public void getNonExistingSubkeyYieldsNull() throws IOException {
|
||||||
assertTrue(lookup.getCertificatesForSubkeyId(6666666).isEmpty());
|
assertTrue(lookup.getCertificateFingerprintsForSubkeyId(6666666).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondInstanceLookupTest() throws IOException, SQLException {
|
public void secondInstanceLookupTest() throws IOException, SQLException {
|
||||||
store("eb85bb5fa33a75e15e944e63f231550c4f47e38e", 1337L);
|
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
|
// do the lookup using a second db instance on the same file
|
||||||
DatabaseSubkeyLookup secondInstance = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
|
DatabaseSubkeyLookup secondInstance = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
|
||||||
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificatesForSubkeyId(1337));
|
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificateFingerprintsForSubkeyId(1337));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class InMemorySubkeyLookup implements SubkeyLookup {
|
||||||
private static final Map<Long, Set<String>> subkeyMap = new HashMap<>();
|
private static final Map<Long, Set<String>> subkeyMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getCertificatesForSubkeyId(long subkeyId) {
|
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) {
|
||||||
Set<String> identifiers = subkeyMap.get(subkeyId);
|
Set<String> identifiers = subkeyMap.get(subkeyId);
|
||||||
if (identifiers == null) {
|
if (identifiers == null) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
|
|
|
@ -56,26 +56,26 @@ public class SubkeyLookupTest {
|
||||||
public void testInsertGet(SubkeyLookup subject) throws IOException {
|
public void testInsertGet(SubkeyLookup subject) throws IOException {
|
||||||
// Initially all null
|
// Initially all null
|
||||||
|
|
||||||
assertTrue(subject.getCertificatesForSubkeyId(123).isEmpty());
|
assertTrue(subject.getCertificateFingerprintsForSubkeyId(123).isEmpty());
|
||||||
assertTrue(subject.getCertificatesForSubkeyId(1337).isEmpty());
|
assertTrue(subject.getCertificateFingerprintsForSubkeyId(1337).isEmpty());
|
||||||
assertTrue(subject.getCertificatesForSubkeyId(420).isEmpty());
|
assertTrue(subject.getCertificateFingerprintsForSubkeyId(420).isEmpty());
|
||||||
|
|
||||||
// Store one val, others still null
|
// Store one val, others still null
|
||||||
|
|
||||||
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(123L));
|
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(123L));
|
||||||
|
|
||||||
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(123));
|
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(123));
|
||||||
assertTrue(subject.getCertificatesForSubkeyId(1337).isEmpty());
|
assertTrue(subject.getCertificateFingerprintsForSubkeyId(1337).isEmpty());
|
||||||
assertTrue(subject.getCertificatesForSubkeyId(420).isEmpty());
|
assertTrue(subject.getCertificateFingerprintsForSubkeyId(420).isEmpty());
|
||||||
|
|
||||||
// Store other val, first stays intact
|
// Store other val, first stays intact
|
||||||
|
|
||||||
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(1337L));
|
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(1337L));
|
||||||
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(420L));
|
subject.storeCertificateSubkeyIds("d1a66e1a23b182c9980f788cfbfcc82a015e7330", Collections.singletonList(420L));
|
||||||
|
|
||||||
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(123));
|
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(123));
|
||||||
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(1337));
|
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(1337));
|
||||||
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificatesForSubkeyId(420));
|
assertEquals(Collections.singleton("d1a66e1a23b182c9980f788cfbfcc82a015e7330"), subject.getCertificateFingerprintsForSubkeyId(420));
|
||||||
|
|
||||||
// add additional entry for subkey
|
// add additional entry for subkey
|
||||||
|
|
||||||
|
@ -83,6 +83,6 @@ public class SubkeyLookupTest {
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
|
new HashSet<>(Arrays.asList("eb85bb5fa33a75e15e944e63f231550c4f47e38e", "d1a66e1a23b182c9980f788cfbfcc82a015e7330")),
|
||||||
subject.getCertificatesForSubkeyId(123));
|
subject.getCertificateFingerprintsForSubkeyId(123));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public abstract class AbstractCertificateStore implements CertificateStore {
|
||||||
|
|
||||||
public Set<Certificate> getCertificatesBySubkeyId(long subkeyId)
|
public Set<Certificate> getCertificatesBySubkeyId(long subkeyId)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Set<String> identifiers = getCertificatesForSubkeyId(subkeyId);
|
Set<String> identifiers = getCertificateFingerprintsForSubkeyId(subkeyId);
|
||||||
if (identifiers.isEmpty()) {
|
if (identifiers.isEmpty()) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface SubkeyLookup {
|
||||||
* @param subkeyId subkey id
|
* @param subkeyId subkey id
|
||||||
* @return fingerprint of the certificate
|
* @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.
|
* Record, which certificate the subkey-ids in the list belong to.
|
||||||
|
|
|
@ -112,8 +112,8 @@ public class SharedPGPCertificateDirectoryAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getCertificatesForSubkeyId(long subkeyId) throws IOException {
|
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException {
|
||||||
return subkeyLookup.getCertificatesForSubkeyId(subkeyId);
|
return subkeyLookup.getCertificateFingerprintsForSubkeyId(subkeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
|
||||||
Set<Long> subkeys = certificate.getSubkeyIds();
|
Set<Long> subkeys = certificate.getSubkeyIds();
|
||||||
assertEquals(expectedSubkeys, subkeys);
|
assertEquals(expectedSubkeys, subkeys);
|
||||||
for (long subkey : subkeys) {
|
for (long subkey : subkeys) {
|
||||||
assertEquals(Collections.singleton(fingerprint), store.getCertificatesForSubkeyId(subkey));
|
assertEquals(Collections.singleton(fingerprint), store.getCertificateFingerprintsForSubkeyId(subkey));
|
||||||
}
|
}
|
||||||
|
|
||||||
Certificate retrieved = store.getCertificate(fingerprint);
|
Certificate retrieved = store.getCertificate(fingerprint);
|
||||||
|
@ -108,7 +108,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
|
||||||
Set<Long> subkeys = certificate.getSubkeyIds();
|
Set<Long> subkeys = certificate.getSubkeyIds();
|
||||||
assertEquals(3, subkeys.size());
|
assertEquals(3, subkeys.size());
|
||||||
for (long subkey : subkeys) {
|
for (long subkey : subkeys) {
|
||||||
assertEquals(Collections.singleton(fingerprint), store.getCertificatesForSubkeyId(subkey));
|
assertEquals(Collections.singleton(fingerprint), store.getCertificateFingerprintsForSubkeyId(subkey));
|
||||||
}
|
}
|
||||||
|
|
||||||
Certificate retrieved = store.getCertificate(fingerprint);
|
Certificate retrieved = store.getCertificate(fingerprint);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue