Struct fog_crypto::hash::HashState

source ·
pub struct HashState { /* private fields */ }
Expand description

A hasher that can incrementally take in data and produce a hash at any time.

Example

// Create a hash by feeding in bytes repeatedly
let mut hash_state = HashState::new();
hash_state.update(b"I am the first part of a data sequence");
let hash_first = hash_state.hash(); // Produce a hash of just the first part
hash_state.update(b"And I am their sibling, the second part of a data sequence");
let hash_full = hash_state.finalize(); // Consume the HashState
println!("hash_first(Base58): {}", hash_first);
println!("hash_full(Base58): {}", hash_full);

Implementations§

source§

impl HashState

source

pub fn new() -> HashState

Initialize a new hasher.

source

pub fn with_version(version: u8) -> Result<HashState, CryptoError>

Initialize a new hasher with a specific algorithm version. You should avoid this except when working through an upgrade process, where you may briefly need to support more than one version. Fails if the version isn’t supported.

source

pub fn version(&self) -> u8

Get the version of hash that this hasher will produce on completion.

source

pub fn update(&mut self, data: impl AsRef<[u8]>)

Update the hasher with new input data.

source

pub fn hash(&self) -> Hash

Get the hash of the data fed into the algorithm so far.

source

pub fn finalize(self) -> Hash

Finalize the hasher and produce a hash. Functions like hash() but consumes the state.

Trait Implementations§

source§

impl Clone for HashState

source§

fn clone(&self) -> HashState

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 Debug for HashState

source§

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

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

impl Default for HashState

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere 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.