Package pgp.cert_d
Class PGPCertificateDirectory
- java.lang.Object
-
- pgp.cert_d.PGPCertificateDirectory
-
- All Implemented Interfaces:
ReadOnlyPGPCertificateDirectory,SubkeyLookup,WritingPGPCertificateDirectory
public class PGPCertificateDirectory extends java.lang.Object implements ReadOnlyPGPCertificateDirectory, WritingPGPCertificateDirectory, SubkeyLookup
Implementation of the Shared PGP Certificate Directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePGPCertificateDirectory.BackendStorage backend.static interfacePGPCertificateDirectory.LockingMechanismInterface for a write-locking mechanism.
-
Constructor Summary
Constructors Constructor Description PGPCertificateDirectory(PGPCertificateDirectory.Backend backend, SubkeyLookup subkeyLookup)Constructor for a PGP certificate directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<java.lang.String>fingerprints()Get the fingerprints of all certificates in the directory, except for certificates which are stored by special name.pgp.certificate_store.certificate.CertificategetByFingerprint(java.lang.String fingerprint)Get the certificate identified by the given fingerprint.pgp.certificate_store.certificate.CertificategetByFingerprintIfChanged(java.lang.String fingerprint, long tag)Get the certificate identified by the given fingerprint if it has changed.pgp.certificate_store.certificate.CertificategetBySpecialName(java.lang.String specialName)Get the certificate identified by the given special name.pgp.certificate_store.certificate.CertificategetBySpecialNameIfChanged(java.lang.String specialName, long tag)Get the certificate identified by the given special name or null, if it has not been changed.java.util.Set<java.lang.String>getCertificateFingerprintsForSubkeyId(long subkeyId)Lookup the fingerprint of the certificate that contains the given subkey.pgp.certificate_store.certificate.KeyMaterialgetTrustRoot()Return the certificate or key identified by the special namepgp.certificate_store.certificate.CertificategetTrustRootCertificate()Get the trust-root certificate.pgp.certificate_store.certificate.CertificategetTrustRootCertificateIfChanged(long tag)Get the trust-root certificate if it has changed.pgp.certificate_store.certificate.Certificateinsert(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a certificate identified by its fingerprint.pgp.certificate_store.certificate.KeyMaterialinsertTrustRoot(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a key or certificate under the special namepgp.certificate_store.certificate.CertificateinsertWithSpecialName(java.lang.String specialName, java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a certificate or key under the given special name.java.util.Iterator<pgp.certificate_store.certificate.Certificate>items()Get all certificates in the directory, except for certificates which are stored by special name.voidstoreCertificateSubkeyIds(java.lang.String certificate, java.util.List<java.lang.Long> subkeyIds)Record, which certificate the subkey-ids in the list belong to.pgp.certificate_store.certificate.CertificatetryInsert(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a certificate identified by its fingerprint.pgp.certificate_store.certificate.KeyMaterialtryInsertTrustRoot(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a key or certificate under the special namepgp.certificate_store.certificate.CertificatetryInsertWithSpecialName(java.lang.String specialName, java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge)Insert a certificate or key under the given special name.
-
-
-
Constructor Detail
-
PGPCertificateDirectory
public PGPCertificateDirectory(PGPCertificateDirectory.Backend backend, SubkeyLookup subkeyLookup)
Constructor for a PGP certificate directory.- Parameters:
backend- storage backendsubkeyLookup- subkey lookup mechanism to map subkey-ids to certificates
-
-
Method Detail
-
getByFingerprint
public pgp.certificate_store.certificate.Certificate getByFingerprint(java.lang.String fingerprint) throws pgp.certificate_store.exception.BadDataException, pgp.certificate_store.exception.BadNameException, java.io.IOExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the certificate identified by the given fingerprint.- Specified by:
getByFingerprintin interfaceReadOnlyPGPCertificateDirectory- Parameters:
fingerprint- lower-case fingerprint of the certificate- Returns:
- certificate
- Throws:
pgp.certificate_store.exception.BadDataException- if the certificate contains bad datapgp.certificate_store.exception.BadNameException- if the fingerprint is malformedjava.io.IOException- in case of an IO error
-
getByFingerprintIfChanged
public pgp.certificate_store.certificate.Certificate getByFingerprintIfChanged(java.lang.String fingerprint, long tag) throws java.io.IOException, pgp.certificate_store.exception.BadNameException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the certificate identified by the given fingerprint if it has changed. This method uses thetag
to calculate, if the certificate might have changed. If the computed tag equals the given tag, the certificate has not changed, sonull
is returned. Otherwise, the changed certificate is returned.- Specified by:
getByFingerprintIfChangedin interfaceReadOnlyPGPCertificateDirectory- Parameters:
fingerprint- lower-case fingerprint of the certificatetag- tag- Returns:
- certificate or null if the certificate has not been changed
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadNameException- if the fingerprint is malformedpgp.certificate_store.exception.BadDataException- if the certificate contains bad data
-
getBySpecialName
public pgp.certificate_store.certificate.Certificate getBySpecialName(java.lang.String specialName) throws pgp.certificate_store.exception.BadNameException, pgp.certificate_store.exception.BadDataException, java.io.IOExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the certificate identified by the given special name.- Specified by:
getBySpecialNamein interfaceReadOnlyPGPCertificateDirectory- Parameters:
specialName- special name- Returns:
- certificate
- Throws:
pgp.certificate_store.exception.BadNameException- if the special name is not knownpgp.certificate_store.exception.BadDataException- if the certificate contains bad datajava.io.IOException- in case of an IO error
-
getBySpecialNameIfChanged
public pgp.certificate_store.certificate.Certificate getBySpecialNameIfChanged(java.lang.String specialName, long tag) throws java.io.IOException, pgp.certificate_store.exception.BadNameException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the certificate identified by the given special name or null, if it has not been changed. This method uses thetag
to calculate, if the certificate might have changed. If the computed tag equals the given tag, the certificate has not changed, sonull
is returned. Otherwise, the changed certificate is returned.- Specified by:
getBySpecialNameIfChangedin interfaceReadOnlyPGPCertificateDirectory- Parameters:
specialName- special nametag- tag- Returns:
- certificate or null
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadNameException- if the special name is not knownpgp.certificate_store.exception.BadDataException- if the certificate contains bad data
-
getTrustRootCertificate
public pgp.certificate_store.certificate.Certificate getTrustRootCertificate() throws java.io.IOException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the trust-root certificate. This is a certificate which is stored under the special nametrust-root
.- Specified by:
getTrustRootCertificatein interfaceReadOnlyPGPCertificateDirectory- Returns:
- trust-root certificate
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the certificate contains bad data
-
getTrustRootCertificateIfChanged
public pgp.certificate_store.certificate.Certificate getTrustRootCertificateIfChanged(long tag) throws java.io.IOException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:ReadOnlyPGPCertificateDirectoryGet the trust-root certificate if it has changed. This method uses thetag
to calculate if the certificate might have changed. If the computed tag equals the given tag, the certificate has not changed, sonull
is returned. Otherwise. the changed certificate is returned.- Specified by:
getTrustRootCertificateIfChangedin interfaceReadOnlyPGPCertificateDirectory- Parameters:
tag- tag- Returns:
- changed certificate, or null if the certificate is unchanged.
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the certificate contains bad data
-
items
public java.util.Iterator<pgp.certificate_store.certificate.Certificate> items()
Description copied from interface:ReadOnlyPGPCertificateDirectoryGet all certificates in the directory, except for certificates which are stored by special name.- Specified by:
itemsin interfaceReadOnlyPGPCertificateDirectory- Returns:
- iterator of certificates
-
fingerprints
public java.util.Iterator<java.lang.String> fingerprints()
Description copied from interface:ReadOnlyPGPCertificateDirectoryGet the fingerprints of all certificates in the directory, except for certificates which are stored by special name.- Specified by:
fingerprintsin interfaceReadOnlyPGPCertificateDirectory- Returns:
- iterator of fingerprints
-
getTrustRoot
public pgp.certificate_store.certificate.KeyMaterial getTrustRoot() throws java.io.IOException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:WritingPGPCertificateDirectoryReturn the certificate or key identified by the special nametrust-root
.- Specified by:
getTrustRootin interfaceWritingPGPCertificateDirectory- Returns:
- trust-root key or certificate
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the certificate contains bad data
-
insertTrustRoot
public pgp.certificate_store.certificate.KeyMaterial insertTrustRoot(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataException, java.lang.InterruptedExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a key or certificate under the special nametrust-root
. This method blocks until the key material has been written.- Specified by:
insertTrustRootin interfaceWritingPGPCertificateDirectory- Parameters:
data- input stream containing the key or certificatemerge- key material merger to merge the key or certificate with existing key material- Returns:
- the merged or inserted key or certificate
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the data stream or the existing trust-root key material contains bad datajava.lang.InterruptedException- if the thread is interrupted
-
tryInsertTrustRoot
public pgp.certificate_store.certificate.KeyMaterial tryInsertTrustRoot(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a key or certificate under the special nametrust-root
. Contrary toWritingPGPCertificateDirectory.insertTrustRoot(InputStream, KeyMaterialMerger), this method does not block. Instead, it returns null if the write-lock cannot be obtained.- Specified by:
tryInsertTrustRootin interfaceWritingPGPCertificateDirectory- Parameters:
data- input stream containing the key or certificatemerge- key material merger to merge the key or certificate with existing key material- Returns:
- the merged or inserted key or certificate, or null if the write-lock cannot be obtained
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the thread is interrupted
-
insert
public pgp.certificate_store.certificate.Certificate insert(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataException, java.lang.InterruptedExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a certificate identified by its fingerprint. This method blocks until the certificate has been written.- Specified by:
insertin interfaceWritingPGPCertificateDirectory- Parameters:
data- input stream containing the certificate datamerge- merge callback to merge the certificate with existing certificate material- Returns:
- the merged or inserted certificate
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the data stream or existing certificate contains bad datajava.lang.InterruptedException- if the thread is interrupted
-
tryInsert
public pgp.certificate_store.certificate.Certificate tryInsert(java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a certificate identified by its fingerprint. Contrary toWritingPGPCertificateDirectory.insert(InputStream, KeyMaterialMerger), this method does not block. Instead, it returns null if the write-lock cannot be obtained.- Specified by:
tryInsertin interfaceWritingPGPCertificateDirectory- Parameters:
data- input stream containing the certificate datamerge- merge callback to merge the certificate with existing certificate material- Returns:
- the merged or inserted certificate
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the data stream or existing certificate contains bad data
-
insertWithSpecialName
public pgp.certificate_store.certificate.Certificate insertWithSpecialName(java.lang.String specialName, java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataException, pgp.certificate_store.exception.BadNameException, java.lang.InterruptedExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a certificate or key under the given special name. This method blocks until the certificate/key has been written.- Specified by:
insertWithSpecialNamein interfaceWritingPGPCertificateDirectory- Parameters:
specialName- special name under which the key material shall be inserteddata- input stream containing the key/certificate datamerge- callback to merge the key/certificate with existing key material- Returns:
- certificate component of the merged or inserted key material data
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the data stream or the existing certificate contains bad datapgp.certificate_store.exception.BadNameException- if the special name is not knownjava.lang.InterruptedException- if the thread is interrupted
-
tryInsertWithSpecialName
public pgp.certificate_store.certificate.Certificate tryInsertWithSpecialName(java.lang.String specialName, java.io.InputStream data, pgp.certificate_store.certificate.KeyMaterialMerger merge) throws java.io.IOException, pgp.certificate_store.exception.BadDataException, pgp.certificate_store.exception.BadNameExceptionDescription copied from interface:WritingPGPCertificateDirectoryInsert a certificate or key under the given special name. Contrary toWritingPGPCertificateDirectory.insertWithSpecialName(String, InputStream, KeyMaterialMerger), this method does not block. Instead, it returns null if the write-lock cannot be obtained.- Specified by:
tryInsertWithSpecialNamein interfaceWritingPGPCertificateDirectory- Parameters:
specialName- special name under which the key material shall be inserteddata- input stream containing the key materialmerge- callback to merge the key/certificate with existing key material- Returns:
- certificate component of the merged or inserted key material
- Throws:
java.io.IOException- in case of an IO errorpgp.certificate_store.exception.BadDataException- if the data stream or existing key material contains bad datapgp.certificate_store.exception.BadNameException- if the special name is not known
-
getCertificateFingerprintsForSubkeyId
public java.util.Set<java.lang.String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws java.io.IOExceptionDescription copied from interface:SubkeyLookupLookup the fingerprint of the certificate that contains the given subkey. If no record is found, return null.- Specified by:
getCertificateFingerprintsForSubkeyIdin interfaceSubkeyLookup- Parameters:
subkeyId- subkey id- Returns:
- fingerprint of the certificate
- Throws:
java.io.IOException- in case of an IO error
-
storeCertificateSubkeyIds
public void storeCertificateSubkeyIds(java.lang.String certificate, java.util.List<java.lang.Long> subkeyIds) throws java.io.IOExceptionDescription copied from interface:SubkeyLookupRecord, which certificate the subkey-ids in the list belong to. This method does not change the affiliation of subkey-ids not contained in the provided list.- Specified by:
storeCertificateSubkeyIdsin interfaceSubkeyLookup- Parameters:
certificate- certificate fingerprintsubkeyIds- subkey ids- Throws:
java.io.IOException- in case of an IO error
-
-