Make Key and Certificate extend KeyMaterial,

get rid of CertificateReader
This commit is contained in:
Paul Schaub 2022-08-08 13:50:59 +02:00
parent 2b5da18fc6
commit 942b287beb
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
7 changed files with 55 additions and 62 deletions

View file

@ -11,14 +11,7 @@ import java.util.Set;
/**
* OpenPGP certificate (public key).
*/
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();
public abstract class Certificate implements KeyMaterial {
/**
* Return an {@link InputStream} of the binary representation of the certificate.

View file

@ -1,29 +0,0 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package pgp.certificate_store;
import pgp.certificate_store.exception.BadDataException;
import java.io.IOException;
import java.io.InputStream;
/**
* Interface definition for a class that can read {@link Certificate Certificates} from binary
* {@link InputStream InputStreams}.
*/
public interface CertificateReaderBackend {
/**
* Read a {@link Certificate} from the given {@link InputStream}.
*
* @param inputStream input stream containing the binary representation of the certificate.
* @return certificate object
*
* @throws IOException in case of an IO error
* @throws BadDataException in case that the input stream does not contain OpenPGP certificate data
*/
Certificate readCertificate(InputStream inputStream) throws IOException, BadDataException;
}

View file

@ -10,7 +10,7 @@ import java.io.InputStream;
/**
* OpenPGP key (secret key).
*/
public abstract class Key {
public abstract class Key implements KeyMaterial {
/**
* Return the certificate part of this OpenPGP key.

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package pgp.certificate_store;
public interface KeyMaterial {
/**
* Return the fingerprint of the certificate as 40 lowercase hex characters.
* TODO: Allow OpenPGP V5 fingerprints
*
* @return fingerprint
*/
String getFingerprint();
}

View file

@ -12,13 +12,13 @@ import java.io.InputStream;
public interface KeyReaderBackend {
/**
* Read a {@link Key} from the given {@link InputStream}.
* Read a {@link KeyMaterial} (either {@link Key} or {@link Certificate}) from the given {@link InputStream}.
*
* @param data input stream containing the binary representation of the key.
* @return key object
* @return key or certificate object
*
* @throws IOException in case of an IO error
* @throws BadDataException in case that the data stream does not contain a valid OpenPGP key
* @throws BadDataException in case that the data stream does not contain a valid OpenPGP key/certificate
*/
Key readKey(InputStream data) throws IOException, BadDataException;
KeyMaterial read(InputStream data) throws IOException, BadDataException;
}