pub trait Hasher<'a, const L: usize> {
// Required methods
fn set_client(&'a self, client: &'a dyn Client<L>);
fn add_data(
&self,
data: SubSlice<'static, u8>,
) -> Result<usize, (ErrorCode, SubSlice<'static, u8>)>;
fn add_mut_data(
&self,
data: SubSliceMut<'static, u8>,
) -> Result<usize, (ErrorCode, SubSliceMut<'static, u8>)>;
fn run(
&'a self,
hash: &'static mut [u8; L],
) -> Result<(), (ErrorCode, &'static mut [u8; L])>;
fn clear_data(&self);
}
Expand description
Computes a non-cryptographic hash over data
‘L’ is the length of the ‘u8’ array to store the hash output.
Required Methods§
sourcefn set_client(&'a self, client: &'a dyn Client<L>)
fn set_client(&'a self, client: &'a dyn Client<L>)
Set the client instance which will receive hash_done()
and
add_data_done()
callbacks.
This callback is called when the data has been added to the hash
engine.
The callback should follow the Client
add_data_done
callback.
sourcefn add_data(
&self,
data: SubSlice<'static, u8>,
) -> Result<usize, (ErrorCode, SubSlice<'static, u8>)>
fn add_data( &self, data: SubSlice<'static, u8>, ) -> Result<usize, (ErrorCode, SubSlice<'static, u8>)>
Add data to the hash block. This is the data that will be used
for the hash function.
Returns the number of bytes parsed on success
There is no guarantee the data has been written until the add_data_done()
callback is fired.
On error the return value will contain a return code and the original data
The possible ErrorCodes are:
- BUSY: The system is busy performing an operation The caller should expect a callback
- SIZE: The size of the
data
buffer is invalid
sourcefn add_mut_data(
&self,
data: SubSliceMut<'static, u8>,
) -> Result<usize, (ErrorCode, SubSliceMut<'static, u8>)>
fn add_mut_data( &self, data: SubSliceMut<'static, u8>, ) -> Result<usize, (ErrorCode, SubSliceMut<'static, u8>)>
Add data to the hash block. This is the data that will be used
for the hash function.
Returns the number of bytes parsed on success
There is no guarantee the data has been written until the add_data_done()
callback is fired.
On error the return value will contain a return code and the original data
The possible ErrorCodes are:
- BUSY: The system is busy performing an operation The caller should expect a callback
- SIZE: The size of the
data
buffer is invalid
sourcefn run(
&'a self,
hash: &'static mut [u8; L],
) -> Result<(), (ErrorCode, &'static mut [u8; L])>
fn run( &'a self, hash: &'static mut [u8; L], ) -> Result<(), (ErrorCode, &'static mut [u8; L])>
Request the implementation to generate a hash and stores the returned
hash in the memory location specified.
This doesn’t return any data, instead the client needs to have
set a hash_done
handler to determine when this is complete.
On error the return value will contain a return code and the original data
If there is data from the add_data()
command asyncrously waiting to
be written it will be written before the operation starts.
The possible ErrorCodes are:
- BUSY: The system is busy performing an operation The caller should expect a callback
- SIZE: The size of the
data
buffer is invalid
sourcefn clear_data(&self)
fn clear_data(&self)
Clear the internal state of the engine. This won’t clear the buffers provided to this API, that is up to the user to clear.