Struct Hasher

Source
pub struct Hasher<N>(/* private fields */);
Expand description

An incremental hash state that can accept any number of writes

The N parameter indicates the security strength level in number of bits. Valid values for it are:

Any other value will fail to compile

§Examples

// hash an input incrementally
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
assert_eq!(hasher.finalize(), marsupial::hash::<KT128>(b"foobarbaz"));

// extended output. `OutputReader` also implements `Read` and `Seek`
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foobarbaz");
let mut output = [0; 1000];
let mut output_reader = hasher.finalize_xof();
output_reader.squeeze(&mut output);
assert_eq!(&output[..32], marsupial::hash::<KT128>(b"foobarbaz").as_bytes());

Implementations§

Source§

impl<N> Hasher<N>
where N: SecurityLevel,

Source

pub const RATE: usize

The number of bytes hashed or output per block

Source

pub fn new() -> Self

Construct a new Hasher for the regular hash function

Source

pub fn update(&mut self, input: &[u8])

Add input bytes to the hash state. You can call this any number of times, until the Hasher is finalized

Source

pub fn finalize(self) -> N::Hash

Finalize the hash state, consuming the Hasher, and return the Hash of the input. This method is equivalent to finalize_custom with an empty customization string

Source

pub fn finalize_custom(self, customization: &[u8]) -> N::Hash

Finalize the hash state, consuming the Hasher, and return the Hash of the input

Source

pub fn finalize_xof(self) -> OutputReader

Finalize the hash state, consuming the Hasher and returning an OutputReader, which can supply any number of output bytes. This method is equivalent to finalize_custom_xof with an empty customization string

Source

pub fn finalize_custom_xof(self, customization: &[u8]) -> OutputReader

Finalize the hash state, consuming the Hasher and returning an OutputReader, which can supply any number of output bytes

Trait Implementations§

Source§

impl<N: Clone> Clone for Hasher<N>

Source§

fn clone(&self) -> Hasher<N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N> Debug for Hasher<N>
where N: SecurityLevel,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N> Default for Hasher<N>
where N: SecurityLevel,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<N> Freeze for Hasher<N>

§

impl<N> RefUnwindSafe for Hasher<N>
where N: RefUnwindSafe,

§

impl<N> Send for Hasher<N>
where N: Send,

§

impl<N> Sync for Hasher<N>
where N: Sync,

§

impl<N> Unpin for Hasher<N>
where N: Unpin,

§

impl<N> UnwindSafe for Hasher<N>
where N: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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.