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>
impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S>
This is the main TicKV struct.
sourcepub fn new(
controller: C,
read_buffer: &'a mut [u8; S],
flash_size: usize,
) -> Self
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
sourcepub fn initialise(&self, hashed_main_key: u64) -> Result<SuccessCode, ErrorCode>
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.
sourcepub fn append_key(
&self,
hash: u64,
value: &[u8],
) -> Result<SuccessCode, ErrorCode>
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.
sourcepub fn get_key(
&self,
hash: u64,
buf: &mut [u8],
) -> Result<(SuccessCode, usize), ErrorCode>
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.
sourcepub fn invalidate_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
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.
sourcepub fn zeroise_key(&self, hash: u64) -> Result<SuccessCode, ErrorCode>
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 1
s in the value and checksum to 0
s. 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.
sourcepub fn garbage_collect(&self) -> Result<usize, ErrorCode>
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.