[][src]Struct sec_store::Store

pub struct Store { /* fields omitted */ }

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

impl Store[src]

pub fn new(user: &[u8], pass: &[u8]) -> Self[src]

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.

pub fn from_inner(
    inner: BTreeMap<u128, Vec<u8>>,
    user: &[u8],
    pass: &[u8]
) -> Self
[src]

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.

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

Accesses inner representation of storage, allowing to serialize it.

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

Consumes self, returning underlying storage.

pub fn len(&self) -> usize[src]

Returns number of key-value pairs

pub fn get_to(&self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>[src]

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.

pub fn get_to_vec(&self, key: &[u8], dest: &mut Vec<u8>) -> Result<usize, ()>[src]

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.

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

Retrieves value for key

Returns None if decryption failed.

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

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

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

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

pub fn remove_to(&mut self, key: &[u8], dest: &mut [u8]) -> Result<usize, ()>[src]

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)

pub fn remove_to_vec(
    &mut self,
    key: &[u8],
    dest: &mut Vec<u8>
) -> Result<usize, ()>
[src]

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.

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

Removes key, returning previous value, if any.

Failing to decrypt, doesn't remove value.

pub fn remove_key(&mut self, key: &[u8]) -> bool[src]

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 RefUnwindSafe for Store

impl Send for Store

impl Sync for Store

impl Unpin for Store

impl UnwindSafe for Store

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.