Sha1State

Struct Sha1State 

Source
pub struct Sha1State(pub NBitWord<u32>, pub NBitWord<u32>, pub NBitWord<u32>, pub NBitWord<u32>, pub NBitWord<u32>);
Expand description

Sha1State represents the state of a SHA-1 hashing process.

It holds intermediate hash calculations. However, it’s important to note that starting a hashing process from an arbitrary Sha1State 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 Sha1State extracted from a Sha1Hasher should not be used with the expectation of continuing the hashing operation from where it left off in the original Sha1Hasher. 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-1 hash operation:

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

let mut default_sha1hasher = Sha1State::default().build_hasher();
default_sha1hasher.write(hello);

let intermediate_state: Sha1State = default_sha1hasher.clone().into();

default_sha1hasher.write(world);

let mut from_sha1state: Sha1Hasher = intermediate_state.into();
from_sha1state.write(world);

let default_hello_world_result = default_sha1hasher.finish();
let from_arbitrary_state_result = from_sha1state.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_sha1hasher and from_sha1state before the Hasher::finish call, the results are different due to from_sha1state be instantiated with an empty pad while the default_sha1hasher’s pad already is populated with b"hello".

Tuple Fields§

§0: NBitWord<u32>§1: NBitWord<u32>§2: NBitWord<u32>§3: NBitWord<u32>§4: NBitWord<u32>

Trait Implementations§

Source§

impl AddAssign<Sha160BitsState> for Sha1State

Source§

fn add_assign(&mut self, rhs: Sha160BitsState)

Performs the += operation. Read more
Source§

impl BuildHasher for Sha1State

Source§

type Hasher = Sha1Hasher

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) -> u64
where T: Hash, Self: Sized, Self::Hasher: Hasher,

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

impl BytesLen for Sha1State

Source§

impl Clone for Sha1State

Source§

fn clone(&self) -> Sha1State

Returns a duplicate 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 Sha1State

Source§

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

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

impl Default for Sha1State

Source§

fn default() -> Self

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

impl From<[u32; 5]> for Sha1State

Source§

fn from(v: [u32; 5]) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 20]> for Sha1State

Source§

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

Converts to this type from the input type.
Source§

impl From<Sha1Hasher> for Sha1State

Source§

fn from(value: Sha1Hasher) -> Self

Converts to this type from the input type.
Source§

impl From<Sha1State> for ByteArrayWrapper<BYTES_LEN>

Source§

fn from(value: Sha1State) -> Self

Converts to this type from the input type.
Source§

impl From<Sha1State> for Sha1Hasher

Source§

fn from(value: Sha1State) -> Self

Converts to this type from the input type.
Source§

impl Hash for Sha1State

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 Sha1State

Source§

type Padding = GenericPad<U64Size, 64, 128>

Source§

type Output = ByteArrayWrapper<BYTES_LEN>

Source§

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

Source§

fn state_to_u64(&self) -> u64

Source§

impl PartialEq for Sha1State

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Sha1State

Source§

impl StructuralPartialEq for Sha1State

Auto Trait Implementations§

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.