Struct openpgp_cert_d::CertD

source ·
pub struct CertD { /* private fields */ }
Expand description

A certificate store.

This is a handle to an on-disk certificate store that can be used to lookup and insert certificates.

Implementations§

source§

impl CertD

source

pub fn new() -> Result<CertD>

Opens the default certificate store.

If not explicitly requested otherwise, an application SHOULD use the default store. To use a store with a different location, use CertD::with_base_dir.

source

pub fn with_base_dir<P: AsRef<Path>>(base: P) -> Result<CertD>

Opens a store with an explicit location.

Note: If not explicitly requested otherwise, an application SHOULD use the default store using CertD::new.

source

pub fn get_base_dir(&self) -> &Path

Get the this Certd’s base path.

source

pub fn get(&self, name: &str) -> Result<Option<(Tag, Data)>>

Looks up a certificate in the store by an name, i.e. a fingerprint or a special name.

If the certificate exists, this function returns Ok(Some((tag, cert))). See Tag for how this can be used to cache lookups.

If the certificate does not exist, this function returns Ok(None).

If an I/O error occurs, or the name was invalid, this function returns an Error.

source

pub fn get_if_changed( &self, since: Tag, name: &str ) -> Result<Option<(Tag, Data)>>

Looks up a certificate in the store by an name, i.e. a fingerprint or a special name, with the Tag from the previous lookup.

If the certificate has changed, this function returns Ok(Some((cert, tag))). The tag can be used in subsequent calls to this function.

If the certificate has not changed or does not exist, this function returns Ok(None).

If an I/O error occurs, or the name was invalid, this function returns an Error.

source

pub fn get_path(&self, name: &str) -> Result<PathBuf>

Get the path to a certificate.

source

pub fn insert<M>(&self, data: Data, merge: M) -> Result<(Tag, Data)>
where M: FnOnce(Data, Option<Data>) -> Result<Data>,

Inserts or updates a cert.

Requires the fingerprint and a callback function. The callback is invoked with an Option<Data> of the existing cert data (if any), and is expected to merge the two copies of the certificate together. The returned Data is written to the store. (Note: The function may decide to omit (parts of) the existing data, but this should be done with great care as not to lose any vital information.)

Acquires lock to the store, blocking the current thread until it’s able to do so.

The insertion method returns the merged certificate data and the tag. See Tag for how this can be used to cache lookups.

source

pub fn try_insert<M>(&self, data: Data, merge: M) -> Result<(Tag, Data)>
where M: FnOnce(Data, Option<Data>) -> Result<Data>,

Inserts or updates a cert, non-blocking variant.

Requires the fingerprint and a callback function. The callback is invoked with an Option<Data> of the existing cert data (if any), and is expected to merge the two copies of the certificate together. The returned Data is written to the store. (Note: The function may decide to omit (parts of) the existing data, but this should be done with great care as not to lose any vital information.)

Attempts to lock the store. Does not block, instead returns an Error::IoError with an std::io::ErrorKind::WouldBlock if the lock cannot be acquired.

The insertion method returns the merged certificate data and the tag. See Tag for how this can be used to cache lookups.

source

pub fn insert_special<M>( &self, special_name: &str, data: Data, merge: M ) -> Result<(Tag, Data)>
where M: FnOnce(Data, Option<Data>) -> Result<Data>,

Inserts or updates the cert or key stored under a special name.

Requires the special name, the cert or key in binary format and a callback function. The callback is invoked with an Option<Data> of the existing data (if any), and is expected to merge the two copies together. The returned Data is written to the store under the special name. (Note: The function may decide to omit (parts of) the existing data, but this should be done with great care as not to lose any vital information.)

Acquires lock to the store, blocking the current thread until it’s able to do so.

The insertion method returns the merged data and the tag. See Tag for how this can be used to cache lookups.

source

pub fn try_insert_special<M>( &self, special_name: &str, data: Data, merge: M ) -> Result<(Tag, Data)>
where M: FnOnce(Data, Option<Data>) -> Result<Data>,

Inserts or updates the cert or key stored under a special name, non-blocking variant.

Requires the special name, the cert or key in binary format and a callback function. The callback is invoked with an Option<Data> of the existing data (if any), and is expected to merge the two copies together. The returned Data is written to the store under the special name. (Note: The function may decide to omit (parts of) the existing data, but this should be done with great care as not to lose any vital information.)

Attempts to lock the store. Does not block, instead returns an Error::IoError with an std::io::ErrorKind::WouldBlock if the lock cannot be acquired.

The insertion method returns the merged data and the tag. See Tag for how this can be used to cache lookups.

source

pub fn iter_fingerprints(&self) -> Result<impl Iterator<Item = String> + '_>

Iterates over the certs in the store returning their fingerprints.

source

pub fn iter(&self) -> Result<impl Iterator<Item = (String, Tag, Data)> + '_>

Iterates over the certs in the store.

Iterates over the certs in the store returning fingerprints, tags, and the data for each cert.

Trait Implementations§

source§

impl Debug for CertD

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for CertD

§

impl Send for CertD

§

impl Sync for CertD

§

impl Unpin for CertD

§

impl UnwindSafe for CertD

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.