Struct tickv::TicKV

source ·
pub struct TicKV<'a, C: FlashController<S>, const S: usize> {
    pub controller: C,
    /* private fields */
}
Expand description

The struct storing all of the TicKV information.

Fields§

§controller: C

The controller used for flash commands

Implementations§

source§

impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S>

This is the main TicKV struct.

source

pub fn new( controller: C, read_buffer: &'a mut [u8; S], flash_size: usize ) -> Self

Create a new struct

C: An implementation of the FlashController trait

controller: An new struct implementing FlashController flash_size: The total size of the flash used for TicKV

source

pub fn initialise(&self, hashed_main_key: u64) -> Result<SuccessCode, ErrorCode>

This function setups the flash region to be used as a key-value store. If the region is already initialised this won’t make any changes.

hashed_main_key: The u64 hash of the const string MAIN_KEY.

If the specified region has not already been setup for TicKV the entire region will be erased.

On success nothing will be returned. On error a ErrorCode will be returned.

source

pub fn append_key( &self, hash: u64, value: &[u8] ) -> Result<SuccessCode, ErrorCode>

Appends the key/value pair to flash storage.

hash: A hashed key. This key will be used in future to retrieve or remove the value. value: A buffer containing the data to be stored to flash.

On success nothing will be returned. On error a ErrorCode will be returned.

source

pub fn get_key( &self, hash: u64, buf: &mut [u8] ) -> Result<(SuccessCode, usize), ErrorCode>

Retrieves the value from flash storage.

  • hash: A hashed key.
  • buf: A buffer to store the value to.

On success a SuccessCode will be returned and the length of the value for the corresponding key. On error a ErrorCode will be returned.

If a power loss occurs before success is returned the data is assumed to be lost.

source

pub fn invalidate_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>

Invalidates the key in flash storage

hash: A hashed key.

On success nothing will be returned. On error a ErrorCode will be returned.

If a power loss occurs before success is returned the data is assumed to be lost.

source

pub fn zeroise_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>

Zeroises the key in flash storage.

This is similar to the invalidate_key() function, but instead will change all 1s in the value and checksum to 0s. This does not remove the header, as that is required for garbage collection later on, so the length and hashed key will still be preserved.

The values will be changed by a single write operation to the flash. The values are not securley overwritten to make restoring data difficult.

Users will need to check with the hardware specifications to determine if this is cryptographically secure for their use case.

https://en.wikipedia.org/wiki/Zeroisation

hash: A hashed key.

On success nothing will be returned. On error a ErrorCode will be returned.

If a power loss occurs before success is returned the data is assumed to be lost.

source

pub fn garbage_collect(&self) -> Result<usize, ErrorCode>

Perform a garbage collection on TicKV

On success the number of bytes freed will be returned. On error a ErrorCode will be returned.

Auto Trait Implementations§

§

impl<'a, C, const S: usize> !Freeze for TicKV<'a, C, S>

§

impl<'a, C, const S: usize> !RefUnwindSafe for TicKV<'a, C, S>

§

impl<'a, C, const S: usize> Send for TicKV<'a, C, S>
where C: Send,

§

impl<'a, C, const S: usize> !Sync for TicKV<'a, C, S>

§

impl<'a, C, const S: usize> Unpin for TicKV<'a, C, S>
where C: Unpin,

§

impl<'a, C, const S: usize> !UnwindSafe for TicKV<'a, C, S>

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

source§

#[doc(hidden)] const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.