2022-08-09 17:50:15 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package pgp.cert_d;
|
|
|
|
|
2022-08-12 14:10:09 +02:00
|
|
|
import pgp.certificate_store.certificate.Certificate;
|
|
|
|
import pgp.certificate_store.certificate.KeyMaterial;
|
|
|
|
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
|
|
|
import pgp.certificate_store.exception.BadDataException;
|
|
|
|
import pgp.certificate_store.exception.BadNameException;
|
2022-08-09 17:50:15 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Interface for a writing OpenPGP certificate directory.
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
public interface WritingPGPCertificateDirectory {
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Return the certificate or key identified by the special name <pre>trust-root</pre>.
|
|
|
|
*
|
|
|
|
* @return trust-root key or certificate
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the certificate contains bad data
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
KeyMaterial getTrustRoot()
|
|
|
|
throws IOException, BadDataException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a key or certificate under the special name <pre>trust-root</pre>.
|
|
|
|
* This method blocks until the key material has been written.
|
|
|
|
*
|
|
|
|
* @param data input stream containing the key or certificate
|
|
|
|
* @param merge key material merger to merge the key or certificate with existing key material
|
|
|
|
* @return the merged or inserted key or certificate
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the data stream or the existing trust-root key material contains bad data
|
|
|
|
* @throws InterruptedException if the thread is interrupted
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
KeyMaterial insertTrustRoot(InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException, InterruptedException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a key or certificate under the special name <pre>trust-root</pre>.
|
|
|
|
* Contrary to {@link #insertTrustRoot(InputStream, KeyMaterialMerger)}, this method does not block.
|
|
|
|
* Instead, it returns null if the write-lock cannot be obtained.
|
|
|
|
*
|
|
|
|
* @param data input stream containing the key or certificate
|
|
|
|
* @param merge key material merger to merge the key or certificate with existing key material
|
|
|
|
* @return the merged or inserted key or certificate, or null if the write-lock cannot be obtained
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the thread is interrupted
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
KeyMaterial tryInsertTrustRoot(InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a certificate identified by its fingerprint.
|
|
|
|
* This method blocks until the certificate has been written.
|
|
|
|
*
|
|
|
|
* @param data input stream containing the certificate data
|
|
|
|
* @param merge merge callback to merge the certificate with existing certificate material
|
|
|
|
* @return the merged or inserted certificate
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the data stream or existing certificate contains bad data
|
|
|
|
* @throws InterruptedException if the thread is interrupted
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
Certificate insert(InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException, InterruptedException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a certificate identified by its fingerprint.
|
|
|
|
* Contrary to {@link #insert(InputStream, KeyMaterialMerger)}, this method does not block.
|
|
|
|
* Instead, it returns null if the write-lock cannot be obtained.
|
|
|
|
*
|
|
|
|
* @param data input stream containing the certificate data
|
|
|
|
* @param merge merge callback to merge the certificate with existing certificate material
|
|
|
|
* @return the merged or inserted certificate
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the data stream or existing certificate contains bad data
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
Certificate tryInsert(InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a certificate or key under the given special name.
|
|
|
|
* This method blocks until the certificate/key has been written.
|
|
|
|
*
|
|
|
|
* @param specialName special name under which the key material shall be inserted
|
|
|
|
* @param data input stream containing the key/certificate data
|
|
|
|
* @param merge callback to merge the key/certificate with existing key material
|
|
|
|
* @return certificate component of the merged or inserted key material data
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the data stream or the existing certificate contains bad data
|
|
|
|
* @throws BadNameException if the special name is not known
|
|
|
|
* @throws InterruptedException if the thread is interrupted
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
Certificate insertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException, BadNameException, InterruptedException;
|
|
|
|
|
2022-08-24 14:53:47 +02:00
|
|
|
/**
|
|
|
|
* Insert a certificate or key under the given special name.
|
|
|
|
* Contrary to {@link #insertWithSpecialName(String, InputStream, KeyMaterialMerger)}, this method does not block.
|
|
|
|
* Instead, it returns null if the write-lock cannot be obtained.
|
|
|
|
*
|
|
|
|
* @param specialName special name under which the key material shall be inserted
|
|
|
|
* @param data input stream containing the key material
|
|
|
|
* @param merge callback to merge the key/certificate with existing key material
|
|
|
|
* @return certificate component of the merged or inserted key material
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws BadDataException if the data stream or existing key material contains bad data
|
|
|
|
* @throws BadNameException if the special name is not known
|
|
|
|
*/
|
2022-08-09 17:50:15 +02:00
|
|
|
Certificate tryInsertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge)
|
|
|
|
throws IOException, BadDataException, BadNameException;
|
|
|
|
|
|
|
|
}
|