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
impl AddAssign<Sha160BitsState> for Sha1State
Source§fn add_assign(&mut self, rhs: Sha160BitsState)
fn add_assign(&mut self, rhs: Sha160BitsState)
+= operation. Read more