Struct CryptoBox

Source
pub struct CryptoBox { /* private fields */ }
Expand description

The CryptoBox encrypted, namespaced document store

See module level documentation for more information.

Implementations§

Source§

impl CryptoBox

Source

pub fn init( path: impl AsRef<Path>, compression: Option<i32>, max_cache_entries: Option<usize>, password: impl AsRef<[u8]>, ) -> Result<Self, CryptoBoxError>

Initialize a new CryptoBox

§Arguments
  • path

    The desired path to the CryptoBox directory. This must be a directory that the user has write permission to, and does not already exist.

  • compression

    The desired zstd compression level for this CryptoBox. Defaults to no compression.

  • max_cache_entries

    The desired maximum number of write-cache entries before a flush automatically occurs. Defaults to 100.

  • password

    The password to encrypt the root string with. This is specified as a byte slice for flexibility.

§Errors
Source

pub fn open( path: impl AsRef<Path>, password: impl AsRef<[u8]>, ) -> Result<Self, CryptoBoxError>

Opens an existing CryptoBox

Will read the default compression and cache settings from the root namespace.

§Arguments
  • path

    The path to the CryptoBox directory.

  • password

    The password to encrypt the root string with. This is specified as a byte slice for flexibility.

§Errors
Source

pub fn namespace_exists(&self, name: &str) -> bool

Check to see if a namespace exists

Source

pub fn namespaces(&self) -> Vec<String>

Get the list of namespaces

Source

pub fn create_namespace(&mut self, name: String) -> Result<(), CryptoBoxError>

Create a namespace

This method will create the namespace with the given name. In the event that the namespace already exists, this method will sort circuit with Ok().

Generates a Uuid and a derived key for the namespace automatically.

§Errors

Will return CryptoBoxError::NamespaceOpen if any underlying errors happen while initializing the new name space.

Source

pub fn get<K, V>( &mut self, key: &K, namespace: &str, ) -> Result<Option<V>, CryptoBoxError>

Gets the specified item from the specified namespace, if it exists

§Arguments
  • key - Key for the key/value pair to be retrieved
  • namespace - The namespace the item was from
§Errors
Source

pub fn get_root<K, V>(&mut self, key: &K) -> Result<Option<V>, CryptoBoxError>

Gets the specified item from the root namespace, if it exists

§Arguments
  • key - Key for the key/value pair to be retrieved
§Errors
Source

pub fn insert<K, V>( &mut self, key: &K, value: &V, namespace: &str, ) -> Result<(), CryptoBoxError>
where K: Serialize, V: Serialize,

Stores the specified item from the specified namespace

§Arguments
  • key - Key for the key/value pair to be stored
  • value - Value for the key/value pair to be stored
  • namespace - The namespace the item will be stored in
§Errors
Source

pub fn insert_root<K, V>( &mut self, key: &K, value: &V, ) -> Result<(), CryptoBoxError>
where K: Serialize, V: Serialize,

Stores the specified item in the root namespace

§Arguments
  • key - Key for the key/value pair to be stored
  • value - Value for the key/value pair to be stored
§Errors
Source

pub fn contains_key<K, V>( &mut self, key: &K, namespace: &str, ) -> Result<bool, CryptoBoxError>

Returns true if the specified namespace contains the provided key

§Arguments
  • key - Key for the key/value pair to be retrieved
  • namespace - The namespace the item was from
§Errors
Source

pub fn flush(&mut self) -> Result<(), CryptoBoxError>

Will flush all of the namespaces in the CryptoBox, including the root namespace.

§Errors

Will return CryptoBoxError::Flush if any underlying errors occur.

Source

pub fn to_hashmap<K, V>( &mut self, namespace: &str, ) -> Result<HashMap<K, V>, CryptoBoxError>

Gets all the key/value pairs in a namespace as HashMap

§Errors

Will return CryptoBoxError::Fetch if there are any underlying errors.

Source

pub fn to_pairs<K, V>( &mut self, namespace: &str, ) -> Result<Vec<(K, V)>, CryptoBoxError>

Gets all the key/value pairs in a namespace as Vec of pairs

§Errors

Will return CryptoBoxError::Fetch if there are any underlying errors.

Source

pub fn root_to_pairs<K, V>(&mut self) -> Result<Vec<(K, V)>, CryptoBoxError>

Gets all the key/value pairs in the root namespace as a Vec of pairs

§Errors

Will return CryptoBoxError::Fetch if there are any underlying errors.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more