pub struct LengthBounds;Expand description
Type that is used to bound the implementations to valid key and output lengths.
We implement SupportsKeyLen and SupportsOutLen for Blake2s<LengthBounds> and
Blake2b<LengthBounds> with the appropriate lengths. This can be used by callers to bound
their own implementations to only accept valid lengths.
§Example
use libcrux_blake2::{Blake2b, Blake2bBuilder, LengthBounds, SupportsKeyLen, SupportsOutLen};
// A function that does a keyed Blake2b and only accepts valid key lengths
fn keyed_hash<const KEY_LEN: usize>(key: &[u8; KEY_LEN], msg: &[u8]) -> [u8; 32]
where
Blake2b<LengthBounds>: SupportsKeyLen<KEY_LEN>,
{
let mut hasher = Blake2bBuilder::new_keyed_const(key)
.build_const_digest_len::<32>();
hasher.update(msg);
let mut output = [0u8; 32];
hasher.finalize(&mut output);
output
}
// This compiles because Blake2b supports 32 byte keys
let key = [0; 32]; // this should actually be random
let msg = b"a test message";
let result = keyed_hash(&key, msg);
Auto Trait Implementations§
impl Freeze for LengthBounds
impl RefUnwindSafe for LengthBounds
impl Send for LengthBounds
impl Sync for LengthBounds
impl Unpin for LengthBounds
impl UnsafeUnpin for LengthBounds
impl UnwindSafe for LengthBounds
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more