mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-16 09:11:08 +01:00
First working prototype
This commit is contained in:
parent
3a690079fe
commit
50243aa6b6
23 changed files with 707 additions and 219 deletions
|
|
@ -0,0 +1,33 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public abstract class Certificate {
|
||||
/**
|
||||
* Return the fingerprint of the certificate as 40 lowercase hex characters.
|
||||
* TODO: Allow OpenPGP V5 fingerprints
|
||||
*
|
||||
* @return fingerprint
|
||||
*/
|
||||
public abstract String getFingerprint();
|
||||
|
||||
/**
|
||||
* Return an {@link InputStream} of the binary representation of the certificate.
|
||||
*
|
||||
* @return input stream
|
||||
*/
|
||||
public abstract InputStream getInputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Return a tag of the certificate.
|
||||
* The tag is a checksum calculated over the binary representation of the certificate.
|
||||
*
|
||||
* @return tag
|
||||
*/
|
||||
public abstract String getTag() throws IOException;
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -6,19 +10,19 @@ import java.util.Iterator;
|
|||
|
||||
public interface CertificateStore {
|
||||
|
||||
Item get(String identifier) throws IOException;
|
||||
Certificate get(String identifier) throws IOException;
|
||||
|
||||
Item getIfChanged(String identifier, String tag) throws IOException;
|
||||
Certificate getIfChanged(String identifier, String tag) throws IOException;
|
||||
|
||||
Item insert(InputStream data, MergeCallback merge) throws IOException;
|
||||
Certificate insert(InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item tryInsert(InputStream data, MergeCallback merge) throws IOException;
|
||||
Certificate tryInsert(InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item insertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
Certificate insertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Item tryInsertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
Certificate tryInsertSpecial(String specialName, InputStream data, MergeCallback merge) throws IOException;
|
||||
|
||||
Iterator<Item> items();
|
||||
Iterator<Certificate> items();
|
||||
|
||||
Iterator<String> fingerprints();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package pgp.certificate_store;
|
||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
package pgp.certificate_store;
|
||||
|
||||
/**
|
||||
* Merge a given certificate (update) with an existing certificate.
|
||||
|
|
@ -11,12 +12,12 @@ 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.
|
||||
* If no existing certificate is found (i.e. existing is null), this method returns the unmodified 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
|
||||
* @param data certificate
|
||||
* @param existing optional already existing copy of the certificate
|
||||
* @return merged certificate
|
||||
*/
|
||||
OutputStream merge(InputStream data, InputStream existing);
|
||||
Certificate merge(Certificate data, Certificate existing);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.certificate_store;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ParserBackend {
|
||||
|
||||
Certificate readCertificate(InputStream inputStream) throws IOException;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* Abstract definitions of an OpenPGP certificate store.
|
||||
*/
|
||||
package pgp.certificate_store;
|
||||
Loading…
Add table
Add a link
Reference in a new issue