From 6ec160835cc94f4657793dd42dd48904097a1fe8 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 25 Jun 2023 14:10:10 +0200 Subject: [PATCH] Allow WebOfTrustCertificateStore to be based on PGPCertificateDirectory --- .../wot/WebOfTrustCertificateStore.java | 96 ++++++++++++++++++- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrustCertificateStore.java b/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrustCertificateStore.java index e3ffc56b..e8b04cb0 100644 --- a/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrustCertificateStore.java +++ b/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrustCertificateStore.java @@ -5,19 +5,31 @@ package org.pgpainless.wot; import pgp.cert_d.PGPCertificateDirectory; +import pgp.cert_d.ReadOnlyPGPCertificateDirectory; +import pgp.cert_d.WritingPGPCertificateDirectory; import pgp.cert_d.subkey_lookup.SubkeyLookup; +import pgp.certificate_store.certificate.KeyMaterial; +import pgp.certificate_store.certificate.KeyMaterialMerger; import pgp.certificate_store.exception.BadDataException; import java.io.IOException; +import java.io.InputStream; import java.util.Iterator; import java.util.NoSuchElementException; import pgp.certificate_store.certificate.Certificate; +import pgp.certificate_store.exception.BadNameException; -public class WebOfTrustCertificateStore extends PGPCertificateDirectory { +public class WebOfTrustCertificateStore implements ReadOnlyPGPCertificateDirectory, WritingPGPCertificateDirectory { - public WebOfTrustCertificateStore(Backend backend, SubkeyLookup subkeyLookup) { - super(backend, subkeyLookup); + private final PGPCertificateDirectory directory; + + public WebOfTrustCertificateStore(PGPCertificateDirectory.Backend backend, SubkeyLookup subkeyLookup) { + this(new PGPCertificateDirectory(backend, subkeyLookup)); + } + + public WebOfTrustCertificateStore(PGPCertificateDirectory certificateDirectory) { + this.directory = certificateDirectory; } public Iterator getAllItems() @@ -30,7 +42,81 @@ public class WebOfTrustCertificateStore extends PGPCertificateDirectory { trustRoot = null; } - Iterator trustRootAndCerts = new PrefixedIterator<>(trustRoot, items()); - return trustRootAndCerts; + return new PrefixedIterator<>(trustRoot, items()); + } + + @Override + public Certificate getTrustRootCertificate() throws IOException, BadDataException { + return directory.getTrustRootCertificate(); + } + + @Override + public Certificate getTrustRootCertificateIfChanged(long tag) throws IOException, BadDataException { + return directory.getTrustRootCertificateIfChanged(tag); + } + + @Override + public Certificate getByFingerprint(String fingerprint) throws IOException, BadNameException, BadDataException { + return directory.getByFingerprint(fingerprint); + } + + @Override + public Certificate getByFingerprintIfChanged(String fingerprint, long tag) throws IOException, BadNameException, BadDataException { + return null; + } + + @Override + public Certificate getBySpecialName(String specialName) throws IOException, BadNameException, BadDataException { + return directory.getBySpecialName(specialName); + } + + @Override + public Certificate getBySpecialNameIfChanged(String specialName, long tag) throws IOException, BadNameException, BadDataException { + return directory.getBySpecialNameIfChanged(specialName, tag); + } + + @Override + public Iterator items() { + return directory.items(); + } + + @Override + public Iterator fingerprints() { + return directory.fingerprints(); + } + + @Override + public KeyMaterial getTrustRoot() throws IOException, BadDataException { + return directory.getTrustRoot(); + } + + @Override + public KeyMaterial insertTrustRoot(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, InterruptedException { + return directory.insertTrustRoot(data, merge); + } + + @Override + public KeyMaterial tryInsertTrustRoot(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException { + return directory.tryInsertTrustRoot(data, merge); + } + + @Override + public Certificate insert(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, InterruptedException { + return directory.insert(data, merge); + } + + @Override + public Certificate tryInsert(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException { + return directory.tryInsert(data, merge); + } + + @Override + public Certificate insertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, BadNameException, InterruptedException { + return directory.insertWithSpecialName(specialName, data, merge); + } + + @Override + public Certificate tryInsertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, BadNameException { + return directory.tryInsertWithSpecialName(specialName, data, merge); } }