Struct rs_sha512::Sha512State

source ·
pub struct Sha512State(pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>);
Expand description

Sha512State represents the state of a SHA-512 hashing process.

It holds intermediate hash calculations. However, it’s important to note that starting a hashing process from an arbitrary Sha512State is not equivalent to resuming the original process that produced that state. Instead, it begins a new hashing process with a different set of initial values.

Therefore, a Sha512State extracted from a Sha512Hasher should not be used with the expectation of continuing the hashing operation from where it left off in the original Sha512Hasher. It is a snapshot of a particular point in the process, not a means to resume the process.

Example

This example demonstrates how to persist the state of a SHA-512 hash operation:

let hello = b"hello";
let world = b" world";

let mut default_sha512hasher = Sha512State::default().build_hasher();
default_sha512hasher.write(hello);

let intermediate_state: Sha512State = default_sha512hasher.clone().into();

default_sha512hasher.write(world);

let mut from_sha512state: Sha512Hasher = intermediate_state.into();
from_sha512state.write(world);

let default_hello_world_result = default_sha512hasher.finish();
let from_arbitrary_state_result = from_sha512state.finish();
assert_ne!(default_hello_world_result, from_arbitrary_state_result);

Note

In this example, even though the internal state are the same between default_sha512hasher and from_sha512state before the Hasher::finish call, the results are different due to from_sha512state be instantiated with an empty pad while the default_sha512hasher’s pad already is populated with b"hello".

Tuple Fields§

§0: NBitWord<u64>§1: NBitWord<u64>§2: NBitWord<u64>§3: NBitWord<u64>§4: NBitWord<u64>§5: NBitWord<u64>§6: NBitWord<u64>§7: NBitWord<u64>

Trait Implementations§

source§

impl AddAssign<Sha512BitsState> for Sha512State

source§

fn add_assign(&mut self, rhs: Sha512BitsState)

Performs the += operation. Read more
source§

impl BuildHasher for Sha512State

§

type Hasher = Sha512Hasher

Type of the hasher that will be created.
source§

fn build_hasher(&self) -> Self::Hasher

Creates a new hasher. Read more
1.71.0 · source§

fn hash_one<T>(&self, x: T) -> u64where T: Hash, Self: Sized, Self::Hasher: Hasher,

Calculates the hash of a single value. Read more
source§

impl BytesLen for Sha512State

source§

impl Clone for Sha512State

source§

fn clone(&self) -> Sha512State

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 Sha512State

source§

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

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

impl Default for Sha512State

source§

fn default() -> Self

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

impl From<[u64; 8]> for Sha512State

source§

fn from(v: [u64; 8]) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 64]> for Sha512State

source§

fn from(v: [u8; 64]) -> Self

Converts to this type from the input type.
source§

impl From<Sha512Hasher> for Sha512State

source§

fn from(value: Sha512Hasher) -> Self

Converts to this type from the input type.
source§

impl From<Sha512State> for ByteArrayWrapper<BYTES_LEN>

source§

fn from(value: Sha512State) -> Self

Converts to this type from the input type.
source§

impl From<Sha512State> for Sha512Hasher

source§

fn from(value: Sha512State) -> Self

Converts to this type from the input type.
source§

impl Hash for Sha512State

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl HashAlgorithm for Sha512State

§

type Padding = GenericPad<U128Size, 128, 128>

§

type Output = ByteArrayWrapper<BYTES_LEN>

source§

fn hash_block(&mut self, bytes: &[u8])

source§

fn state_to_u64(&self) -> u64

source§

impl PartialEq<Sha512State> for Sha512State

source§

fn eq(&self, other: &Sha512State) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Sha512State

source§

impl StructuralEq for Sha512State

source§

impl StructuralPartialEq for Sha512State

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