CertStoreConn

Struct CertStoreConn 

Source
pub struct CertStoreConn<P: AsRef<Path>> { /* private fields */ }
Expand description

A CertStore connection builder.

An instance of this struct is returned by CertStore::open and can be configured using exposed methods. In simple terms:

§Example

Start a connection with custom password hashing parameters.

use pyrus_cert_store::CertStore;

let store = CertStore::open("certstore.db3")
    // 20 blocks of memory used, 3 threads, 4 iterations
    .with_params(20 * 1024, 3, 4)
    .with_passphrase(String::from("password123"), b"use a better password and salt")
    .connect()?;

Implementations§

Source§

impl<P: AsRef<Path>> CertStoreConn<P>

Source

pub fn with_params(self, memory: u32, threads: u32, iterations: u32) -> Self

Modifies the parameters used for the Argon2 password hashing algorithm. For detailed information about these parameters read the argon2 crate documentation.

In simple terms:

  • memory - the number of 1 KiB memory blocks,
  • threads - the number of threads used for calculations,
  • iterations - the number of passes through the algorithm.
Source

pub fn with_passphrase<S: AsRef<[u8]>>( self, passphrase: String, salt: S, ) -> Self

Sets a passphrase to be used for the connection. Not calling this method is equivalent to not enabling encryption for the CertStore.

§Example

Using a wrong password results in an error

let store_file = Path::new("certstore.db3");
{
    let store = CertStore::open(store_file)
        .with_passphrase(String::from("1234"), b"saltysalt")
        .connect()?;
} // drops the connection
{
    // reconnect with a wrong password
    let store = CertStore::open(store_file)
        .with_passphrase(String::from("banana"), b"saltysalt")
        .connect();

    assert!(store.is_err());
}
Source

pub fn connect(self) -> Result<CertStore>

Attempts the connection to the underlying SQL database. If the database does not exist, it is created and initialized.

§Errors

Trait Implementations§

Source§

impl<P: AsRef<Path>> Drop for CertStoreConn<P>

Zeroizes the passphrase and salt on drop. This is for security reasons to not leave the passphrase in memory after opening the connection.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<P> Freeze for CertStoreConn<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for CertStoreConn<P>
where P: RefUnwindSafe,

§

impl<P> Send for CertStoreConn<P>
where P: Send,

§

impl<P> Sync for CertStoreConn<P>
where P: Sync,

§

impl<P> Unpin for CertStoreConn<P>
where P: Unpin,

§

impl<P> UnwindSafe for CertStoreConn<P>
where P: UnwindSafe,

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.