pub struct Store { /* private fields */ }Expand description
Secure storage API
Values are stored in memory encrypted, user can save storages manually
and lately restore it using serde
Key is stored as hash, while Value is stored as encrypted bytes.
Implementations§
Source§impl Store
impl Store
Sourcepub fn new(user: &[u8], pass: &[u8]) -> Self
pub fn new(user: &[u8], pass: &[u8]) -> Self
Creates new instance using creds.
Parameters:
user- user specific information that can distinguish him from others.pass- can be any number of arbitrary bytes except it MUST NOT be zero length.
Sourcepub fn from_inner(
inner: BTreeMap<u128, Vec<u8>>,
user: &[u8],
pass: &[u8],
) -> Self
pub fn from_inner( inner: BTreeMap<u128, Vec<u8>>, user: &[u8], pass: &[u8], ) -> Self
Creates new instance using provided storage and pass.
Parameters:
storage- already initialized storage, only can work with storage that is returned bySelf::inner.user- user specific information that can distinguish him from others.pass- can be any number of arbitrary bytes except it MUST NOT be zero length.
Sourcepub fn inner(&self) -> &BTreeMap<u128, Vec<u8>>
pub fn inner(&self) -> &BTreeMap<u128, Vec<u8>>
Accesses inner representation of storage, allowing to serialize it.
Sourcepub fn into_inner(self) -> BTreeMap<u128, Vec<u8>>
pub fn into_inner(self) -> BTreeMap<u128, Vec<u8>>
Consumes self, returning underlying storage.
Sourcepub fn get_to(&self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>
pub fn get_to(&self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>
Retrieves value for key, storing decrypted value in dest.
Returns Err when key doesn’t exist or user has no permission to read it.
Otherwise returns number of bytes written, or ‘0’ in case of insufficient storage.
Sourcepub fn get_to_vec(&self, key: &[u8], dest: &mut Vec<u8>) -> Result<usize, ()>
pub fn get_to_vec(&self, key: &[u8], dest: &mut Vec<u8>) -> Result<usize, ()>
Retrieves value for key to store in dest, resulting in it being overwritten.
Returns Err when key doesn’t exist or user has no permission to read it.
Otherwise returns number of bytes written.
Sourcepub fn get(&self, key: &[u8]) -> Option<Vec<u8>>
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>
Retrieves value for key
Returns None if decryption failed.
Sourcepub fn insert_owned(&mut self, key: &[u8], value: Vec<u8>) -> Option<Vec<u8>>
pub fn insert_owned(&mut self, key: &[u8], value: Vec<u8>) -> Option<Vec<u8>>
Inserts new owned value for key, returning previous one, if any.
Sourcepub fn insert(&mut self, key: &[u8], value: &[u8]) -> Option<Vec<u8>>
pub fn insert(&mut self, key: &[u8], value: &[u8]) -> Option<Vec<u8>>
Inserts new value for key, returning previous one, if any.
Sourcepub fn remove_to(&mut self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>
pub fn remove_to(&mut self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>
Extracts value under key to specified dest
Returns Err when key doesn’t exist, or user has no permission to read it.
Otherwise returns number of bytes written, or ‘0’ in case of insufficient storage.
Note that value is removed only if Ok(size) >= Ok(1)
Sourcepub fn remove_to_vec(
&mut self,
key: &[u8],
dest: &mut Vec<u8>,
) -> Result<usize, ()>
pub fn remove_to_vec( &mut self, key: &[u8], dest: &mut Vec<u8>, ) -> Result<usize, ()>
Extracts value under key to specified dest
Returns Err when key doesn’t exist, or user has no permission to read it.
Otherwise returns number of bytes written.
Sourcepub fn remove(&mut self, key: &[u8]) -> Option<Vec<u8>>
pub fn remove(&mut self, key: &[u8]) -> Option<Vec<u8>>
Removes key, returning previous value, if any.
Failing to decrypt, doesn’t remove value.
Sourcepub fn remove_key(&mut self, key: &[u8]) -> bool
pub fn remove_key(&mut self, key: &[u8]) -> bool
Removes key, returning whether it was set previously.
Note that it only removes value, without checking if you can read it.