pub struct CryptoBox { /* private fields */ }
Expand description
The CryptoBox
encrypted, namespaced document store
See module level documentation for more information.
Implementations§
Source§impl CryptoBox
impl CryptoBox
Sourcepub fn init(
path: impl AsRef<Path>,
compression: Option<i32>,
max_cache_entries: Option<usize>,
password: impl AsRef<[u8]>,
) -> Result<Self, CryptoBoxError>
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
CryptoBoxError::DirectoryAlreadyExists
if the desired path already existsCryptoBoxError::FailedCreatingDirectory
,CryptoBoxError::RootKeyIO
, orCryptoBoxError::RootNamespaceInit
if an IO error creating theCryptoBox
occurs
Sourcepub fn open(
path: impl AsRef<Path>,
password: impl AsRef<[u8]>,
) -> Result<Self, CryptoBoxError>
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
CryptoBoxError::DirectoryDoesNotExist
if the directory does not existCryptoBoxError::RootKeyDecryption
if the root key fails to decryptCryptoBoxError::MissingConfiguration
if the configuration control structure is missingCryptoBoxError::RootKeyIO
,CryptoBoxError::MissingNamespaceDirectory
, orCryptoBoxError::RootNamespaceOpen
if something goes wrong with IO while opening
Sourcepub fn namespace_exists(&self, name: &str) -> bool
pub fn namespace_exists(&self, name: &str) -> bool
Check to see if a namespace exists
Sourcepub fn namespaces(&self) -> Vec<String>
pub fn namespaces(&self) -> Vec<String>
Get the list of namespaces
Sourcepub fn create_namespace(&mut self, name: String) -> Result<(), CryptoBoxError>
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.
Sourcepub fn get<K, V>(
&mut self,
key: &K,
namespace: &str,
) -> Result<Option<V>, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
pub fn get<K, V>(
&mut self,
key: &K,
namespace: &str,
) -> Result<Option<V>, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
Gets the specified item from the specified namespace, if it exists
§Arguments
key
- Key for the key/value pair to be retrievednamespace
- The namespace the item was from
§Errors
CryptoBoxError::NoSuchNamespace
if the namespace does not existCryptoBoxError::Fetch
if an underlying error occurs
Sourcepub fn get_root<K, V>(&mut self, key: &K) -> Result<Option<V>, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
pub fn get_root<K, V>(&mut self, key: &K) -> Result<Option<V>, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
Gets the specified item from the root namespace, if it exists
§Arguments
key
- Key for the key/value pair to be retrieved
§Errors
CryptoBoxError::Fetch
if an underlying error occurs
Sourcepub fn insert<K, V>(
&mut self,
key: &K,
value: &V,
namespace: &str,
) -> Result<(), CryptoBoxError>
pub fn insert<K, V>( &mut self, key: &K, value: &V, namespace: &str, ) -> Result<(), CryptoBoxError>
Stores the specified item from the specified namespace
§Arguments
key
- Key for the key/value pair to be storedvalue
- Value for the key/value pair to be storednamespace
- The namespace the item will be stored in
§Errors
CryptoBoxError::NoSuchNamespace
if the namespace does not existCryptoBoxError::Store
if an underlying error occurs
Sourcepub fn insert_root<K, V>(
&mut self,
key: &K,
value: &V,
) -> Result<(), CryptoBoxError>
pub fn insert_root<K, V>( &mut self, key: &K, value: &V, ) -> Result<(), CryptoBoxError>
Stores the specified item in the root namespace
§Arguments
key
- Key for the key/value pair to be storedvalue
- Value for the key/value pair to be stored
§Errors
CryptoBoxError::Store
if an underlying error occurs
Sourcepub fn contains_key<K, V>(
&mut self,
key: &K,
namespace: &str,
) -> Result<bool, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
pub fn contains_key<K, V>(
&mut self,
key: &K,
namespace: &str,
) -> Result<bool, CryptoBoxError>where
K: Serialize,
V: DeserializeOwned,
Returns true if the specified namespace contains the provided key
§Arguments
key
- Key for the key/value pair to be retrievednamespace
- The namespace the item was from
§Errors
CryptoBoxError::NoSuchNamespace
if the namespace does not existCryptoBoxError::Fetch
if an underlying error occurs
Sourcepub fn flush(&mut self) -> Result<(), CryptoBoxError>
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.
Sourcepub fn to_hashmap<K, V>(
&mut self,
namespace: &str,
) -> Result<HashMap<K, V>, CryptoBoxError>
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.
Sourcepub fn to_pairs<K, V>(
&mut self,
namespace: &str,
) -> Result<Vec<(K, V)>, CryptoBoxError>
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.
Sourcepub fn root_to_pairs<K, V>(&mut self) -> Result<Vec<(K, V)>, CryptoBoxError>
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.