Store

Struct Store 

Source
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

Source

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.
Source

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 by Self::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.
Source

pub fn inner(&self) -> &BTreeMap<u128, Vec<u8>>

Accesses inner representation of storage, allowing to serialize it.

Source

pub fn into_inner(self) -> BTreeMap<u128, Vec<u8>>

Consumes self, returning underlying storage.

Source

pub fn len(&self) -> usize

Returns number of key-value pairs

Source

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.

Source

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.

Source

pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>

Retrieves value for key

Returns None if decryption failed.

Source

pub fn contains(&self, key: &[u8]) -> bool

Checks for key presence within storage

Source

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.

Source

pub fn insert(&mut self, key: &[u8], value: &[u8]) -> Option<Vec<u8>>

Inserts new value for key, returning previous one, if any.

Source

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)

Source

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.

Source

pub fn remove(&mut self, key: &[u8]) -> Option<Vec<u8>>

Removes key, returning previous value, if any.

Failing to decrypt, doesn’t remove value.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

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