mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2024-12-22 13:47:59 +01:00
Wip
This commit is contained in:
parent
9efcae77de
commit
dec37c4706
14 changed files with 98 additions and 49 deletions
|
@ -4,13 +4,13 @@
|
|||
|
||||
package pgp.cert_d;
|
||||
|
||||
import pgp.certificate_store.CertificateReaderBackend;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
import pgp.CertificateMerger;
|
||||
import pgp.CertificateReader;
|
||||
|
||||
public abstract class BackendProvider {
|
||||
|
||||
public abstract CertificateReaderBackend provideCertificateReaderBackend();
|
||||
public abstract CertificateReader provideCertificateReaderBackend();
|
||||
|
||||
public abstract MergeCallback provideDefaultMergeCallback();
|
||||
public abstract CertificateMerger provideDefaultMergeCallback();
|
||||
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
package pgp.cert_d;
|
||||
|
||||
import pgp.Certificate;
|
||||
import pgp.CertificateMerger;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -127,7 +127,7 @@ public class CachingSharedPGPCertificateDirectoryWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate insert(InputStream data, MergeCallback merge)
|
||||
public Certificate insert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, InterruptedException {
|
||||
Certificate certificate = underlyingCertificateDirectory.insert(data, merge);
|
||||
remember(certificate.getFingerprint(), certificate);
|
||||
|
@ -135,7 +135,7 @@ public class CachingSharedPGPCertificateDirectoryWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate tryInsert(InputStream data, MergeCallback merge)
|
||||
public Certificate tryInsert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException {
|
||||
Certificate certificate = underlyingCertificateDirectory.tryInsert(data, merge);
|
||||
if (certificate != null) {
|
||||
|
@ -145,7 +145,7 @@ public class CachingSharedPGPCertificateDirectoryWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate insertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
public Certificate insertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, BadNameException, InterruptedException {
|
||||
Certificate certificate = underlyingCertificateDirectory.insertWithSpecialName(specialName, data, merge);
|
||||
remember(specialName, certificate);
|
||||
|
@ -153,7 +153,7 @@ public class CachingSharedPGPCertificateDirectoryWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate tryInsertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
public Certificate tryInsertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, BadNameException {
|
||||
Certificate certificate = underlyingCertificateDirectory.tryInsertWithSpecialName(specialName, data, merge);
|
||||
if (certificate != null) {
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
package pgp.cert_d;
|
||||
|
||||
import pgp.Certificate;
|
||||
import pgp.CertificateMerger;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
|
||||
public interface SharedPGPCertificateDirectory {
|
||||
|
||||
LockingMechanism getLock();
|
||||
|
@ -29,16 +29,16 @@ public interface SharedPGPCertificateDirectory {
|
|||
Certificate getBySpecialNameIfChanged(String specialName, String tag)
|
||||
throws IOException, BadNameException, BadDataException;
|
||||
|
||||
Certificate insert(InputStream data, MergeCallback merge)
|
||||
Certificate insert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, InterruptedException;
|
||||
|
||||
Certificate tryInsert(InputStream data, MergeCallback merge)
|
||||
Certificate tryInsert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException;
|
||||
|
||||
Certificate insertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
Certificate insertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, BadNameException, InterruptedException;
|
||||
|
||||
Certificate tryInsertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
Certificate tryInsertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, BadNameException;
|
||||
|
||||
Iterator<Certificate> items();
|
||||
|
|
|
@ -16,32 +16,32 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import pgp.Certificate;
|
||||
import pgp.CertificateMerger;
|
||||
import pgp.CertificateReader;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
import pgp.certificate_store.exception.NotAStoreException;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.CertificateReaderBackend;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
|
||||
public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDirectory {
|
||||
|
||||
private final FilenameResolver resolver;
|
||||
private final LockingMechanism writeLock;
|
||||
private final CertificateReaderBackend certificateReaderBackend;
|
||||
private final CertificateReader certificateReaderBackend;
|
||||
|
||||
public SharedPGPCertificateDirectoryImpl(BackendProvider backendProvider)
|
||||
throws NotAStoreException {
|
||||
this(backendProvider.provideCertificateReaderBackend());
|
||||
}
|
||||
|
||||
public SharedPGPCertificateDirectoryImpl(CertificateReaderBackend certificateReaderBackend)
|
||||
public SharedPGPCertificateDirectoryImpl(CertificateReader certificateReaderBackend)
|
||||
throws NotAStoreException {
|
||||
this(
|
||||
BaseDirectoryProvider.getDefaultBaseDir(),
|
||||
certificateReaderBackend);
|
||||
}
|
||||
|
||||
public SharedPGPCertificateDirectoryImpl(File baseDirectory, CertificateReaderBackend certificateReaderBackend)
|
||||
public SharedPGPCertificateDirectoryImpl(File baseDirectory, CertificateReader certificateReaderBackend)
|
||||
throws NotAStoreException {
|
||||
this(
|
||||
certificateReaderBackend,
|
||||
|
@ -50,7 +50,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
}
|
||||
|
||||
public SharedPGPCertificateDirectoryImpl(
|
||||
CertificateReaderBackend certificateReaderBackend,
|
||||
CertificateReader certificateReaderBackend,
|
||||
FilenameResolver filenameResolver,
|
||||
LockingMechanism writeLock)
|
||||
throws NotAStoreException {
|
||||
|
@ -131,7 +131,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate insert(InputStream data, MergeCallback merge)
|
||||
public Certificate insert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, InterruptedException {
|
||||
writeLock.lockDirectory();
|
||||
|
||||
|
@ -142,7 +142,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate tryInsert(InputStream data, MergeCallback merge)
|
||||
public Certificate tryInsert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException {
|
||||
if (!writeLock.tryLockDirectory()) {
|
||||
return null;
|
||||
|
@ -154,7 +154,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
return certificate;
|
||||
}
|
||||
|
||||
private Certificate _insert(InputStream data, MergeCallback merge)
|
||||
private Certificate _insert(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException {
|
||||
Certificate newCertificate = certificateReaderBackend.readCertificate(data);
|
||||
Certificate existingCertificate;
|
||||
|
@ -196,7 +196,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate insertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
public Certificate insertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadNameException, BadDataException, InterruptedException {
|
||||
writeLock.lockDirectory();
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
}
|
||||
|
||||
@Override
|
||||
public Certificate tryInsertWithSpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
public Certificate tryInsertWithSpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadNameException, BadDataException {
|
||||
if (!writeLock.tryLockDirectory()) {
|
||||
return null;
|
||||
|
@ -219,7 +219,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
return certificate;
|
||||
}
|
||||
|
||||
private Certificate _insertSpecial(String specialName, InputStream data, MergeCallback merge)
|
||||
private Certificate _insertSpecial(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadNameException, BadDataException {
|
||||
Certificate newCertificate = certificateReaderBackend.readCertificate(data);
|
||||
Certificate existingCertificate = getBySpecialName(specialName);
|
||||
|
|
|
@ -24,6 +24,8 @@ dependencies {
|
|||
// Logging
|
||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
|
||||
api project(":pgp-certificates")
|
||||
}
|
||||
|
||||
animalsniffer {
|
||||
|
|
|
@ -6,6 +6,7 @@ package pgp.certificate_store;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.Certificate;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package pgp.certificate_store;
|
||||
|
||||
import pgp.Certificate;
|
||||
import pgp.CertificateMerger;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
|
||||
|
@ -50,12 +52,12 @@ public interface CertificateDirectory {
|
|||
|
||||
/**
|
||||
* Insert a certificate into the store.
|
||||
* If an instance of the certificate is already present in the store, the given {@link MergeCallback} will be
|
||||
* If an instance of the certificate is already present in the store, the given {@link CertificateMerger} will be
|
||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
||||
* will be stored in the store and returned.
|
||||
*
|
||||
* This method will block until a write-lock on the store can be acquired. If you cannot afford blocking,
|
||||
* consider to use {@link #tryInsertCertificate(InputStream, MergeCallback)} instead.
|
||||
* consider to use {@link #tryInsertCertificate(InputStream, CertificateMerger)} instead.
|
||||
*
|
||||
* @param data input stream containing the new certificate instance
|
||||
* @param merge callback for merging with an existing certificate instance
|
||||
|
@ -64,12 +66,12 @@ public interface CertificateDirectory {
|
|||
* @throws IOException in case of an IO-error
|
||||
* @throws InterruptedException in case the inserting thread gets interrupted
|
||||
*/
|
||||
Certificate insertCertificate(InputStream data, MergeCallback merge)
|
||||
Certificate insertCertificate(InputStream data, CertificateMerger merge)
|
||||
throws IOException, InterruptedException, BadDataException;
|
||||
|
||||
/**
|
||||
* Insert a certificate into the store.
|
||||
* If an instance of the certificate is already present in the store, the given {@link MergeCallback} will be
|
||||
* If an instance of the certificate is already present in the store, the given {@link CertificateMerger} will be
|
||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
||||
* will be stored in the store and returned.
|
||||
*
|
||||
|
@ -84,19 +86,19 @@ public interface CertificateDirectory {
|
|||
*
|
||||
* @throws IOException in case of an IO-error
|
||||
*/
|
||||
Certificate tryInsertCertificate(InputStream data, MergeCallback merge)
|
||||
Certificate tryInsertCertificate(InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException;
|
||||
|
||||
/**
|
||||
* Insert a certificate into the store.
|
||||
* The certificate will be stored under the given special name instead of its fingerprint.
|
||||
*
|
||||
* If an instance of the certificate is already present under the special name in the store, the given {@link MergeCallback} will be
|
||||
* If an instance of the certificate is already present under the special name in the store, the given {@link CertificateMerger} will be
|
||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
||||
* will be stored in the store and returned.
|
||||
*
|
||||
* This method will block until a write-lock on the store can be acquired. If you cannot afford blocking,
|
||||
* consider to use {@link #tryInsertCertificateBySpecialName(String, InputStream, MergeCallback)} instead.
|
||||
* consider to use {@link #tryInsertCertificateBySpecialName(String, InputStream, CertificateMerger)} instead.
|
||||
*
|
||||
* @param data input stream containing the new certificate instance
|
||||
* @param merge callback for merging with an existing certificate instance
|
||||
|
@ -104,14 +106,14 @@ public interface CertificateDirectory {
|
|||
*
|
||||
* @throws IOException in case of an IO-error
|
||||
*/
|
||||
Certificate insertCertificateBySpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
Certificate insertCertificateBySpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, InterruptedException, BadDataException, BadNameException;
|
||||
|
||||
/**
|
||||
* Insert a certificate into the store.
|
||||
* The certificate will be stored under the given special name instead of its fingerprint.
|
||||
*
|
||||
* If an instance of the certificate is already present under the special name in the store, the given {@link MergeCallback} will be
|
||||
* If an instance of the certificate is already present under the special name in the store, the given {@link CertificateMerger} will be
|
||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
||||
* will be stored in the store and returned.
|
||||
*
|
||||
|
@ -126,7 +128,7 @@ public interface CertificateDirectory {
|
|||
*
|
||||
* @throws IOException in case of an IO-error
|
||||
*/
|
||||
Certificate tryInsertCertificateBySpecialName(String specialName, InputStream data, MergeCallback merge)
|
||||
Certificate tryInsertCertificateBySpecialName(String specialName, InputStream data, CertificateMerger merge)
|
||||
throws IOException, BadDataException, BadNameException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package pgp.certificate_store.exception;
|
||||
|
||||
/**
|
||||
* Provided name was neither a valid fingerprint, nor a known special name.
|
||||
* Thrown when a bad name for a cert was used.
|
||||
*/
|
||||
public class BadNameException extends Exception {
|
||||
|
||||
|
|
35
pgp-certificates/build.gradle
Normal file
35
pgp-certificates/build.gradle
Normal file
|
@ -0,0 +1,35 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group 'org.pgpainless'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'ru.vyarus.animalsniffer'
|
||||
|
||||
dependencies {
|
||||
// animal sniffer
|
||||
signature "net.sf.androidscents.signature:android-api-level-${minAndroidSdk}:2.3.3_r2@signature"
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
// Logging
|
||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
}
|
||||
|
||||
animalsniffer {
|
||||
sourceSets = [sourceSets.main]
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
package pgp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
|
@ -2,14 +2,14 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
package pgp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Merge a given certificate (update) with an existing certificate.
|
||||
*/
|
||||
public interface MergeCallback {
|
||||
public interface CertificateMerger {
|
||||
|
||||
/**
|
||||
* Merge the given certificate data with the existing certificate and return the result.
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
package pgp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -11,7 +11,7 @@ import java.io.InputStream;
|
|||
* Interface definition for a class that can read {@link Certificate Certificates} from binary
|
||||
* {@link InputStream InputStreams}.
|
||||
*/
|
||||
public interface CertificateReaderBackend {
|
||||
public interface CertificateReader {
|
||||
|
||||
/**
|
||||
* Read a {@link Certificate} from the given {@link InputStream}.
|
8
pgp-certificates/src/main/java/pgp/package-info.java
Normal file
8
pgp-certificates/src/main/java/pgp/package-info.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* OpenPGP Certificates.
|
||||
*/
|
||||
package pgp;
|
|
@ -6,5 +6,6 @@ rootProject.name = 'cert-d-java'
|
|||
|
||||
include 'pgp-cert-d-java',
|
||||
'pgp-cert-d-java-jdbc-sqlite-lookup',
|
||||
'pgp-certificate-store'
|
||||
'pgp-certificate-store',
|
||||
'pgp-certificates'
|
||||
|
||||
|
|
Loading…
Reference in a new issue