mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-16 09:11:08 +01:00
Module structure
This commit is contained in:
parent
9d2f06b14e
commit
3a690079fe
14 changed files with 381 additions and 58 deletions
25
pgp-certificate-store/build.gradle
Normal file
25
pgp-certificate-store/build.gradle
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group 'org.pgpainless'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
// Logging
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package pgp.certificate_store;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface CertificateStore {
|
||||
|
||||
Item get(String identifier) throws IOException;
|
||||
|
||||
Item getIfChanged(String identifier, String tag) throws IOException;
|
||||
|
||||
Item insert(InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item tryInsert(InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item insertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item tryInsertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Iterator<Item> items();
|
||||
|
||||
Iterator<String> fingerprints();
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package pgp.certificate_store;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Item {
|
||||
|
||||
private final String fingerprint;
|
||||
private final String tag;
|
||||
private final InputStream data;
|
||||
|
||||
public Item(String fingerprint, String tag, InputStream data) {
|
||||
this.fingerprint = fingerprint;
|
||||
this.tag = tag;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fingerprint of the certificate.
|
||||
*
|
||||
* @return certificate fingerprint
|
||||
*/
|
||||
public String getFingerprint() {
|
||||
return fingerprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tag used to check if the certificate was changed between retrievals.
|
||||
*
|
||||
* @return tag
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an {@link InputStream} containing the certificate data.
|
||||
*
|
||||
* @return data
|
||||
*/
|
||||
public InputStream getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package pgp.certificate_store;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Merge a given certificate (update) with an existing certificate.
|
||||
*/
|
||||
public interface MergeCallback {
|
||||
|
||||
/**
|
||||
* Merge the given certificate data with the existing certificate and return the result.
|
||||
*
|
||||
* If no existing certificate is found (i.e. existing is null), this method returns the binary representation of data.
|
||||
*
|
||||
* @param data input stream containing the certificate
|
||||
* @param existing optional input stream containing an already existing copy of the certificate
|
||||
* @return output stream containing the binary representation of the merged certificate
|
||||
*/
|
||||
OutputStream merge(InputStream data, InputStream existing);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue