pub struct Hasher { /* private fields */ }Expand description
An incremental hasher, implemented by the VM.
A value of this type is meaningful only in the current contract invocation, so it can’t be stored.
Implementations§
Source§impl Hasher
impl Hasher
Sourcepub fn new() -> Hasher
pub fn new() -> Hasher
Get a hasher.
Throws a syscall exception if the VM refuses the stream — its
live-stream cap (the chain’s max_sha256_buffers network config
parameter) is reached.
Sourcepub fn try_new() -> SysResult<Hasher>
pub fn try_new() -> SysResult<Hasher>
Get a hasher if the VM has a free stream, or the refusing syscall’s error.
Sourcepub fn update<I: AsRef<[u8]>>(&mut self, input: &I)
pub fn update<I: AsRef<[u8]>>(&mut self, input: &I)
Append data to the hasher input.
Throws a syscall exception (aborting the frame) if the host call fails.
Sourcepub fn fork(&self) -> Hasher
pub fn fork(&self) -> Hasher
Fork the hasher: a new hasher with a copy of the absorbed state, after which the two diverge independently. The copy is constant-time in the VM, so absorb a shared prefix once and fork per suffix.
Throws a syscall exception if the VM refuses the stream.
Sourcepub fn try_fork(&self) -> SysResult<Hasher>
pub fn try_fork(&self) -> SysResult<Hasher>
Fork the hasher if the VM has a free stream (see
fork), or the refusing syscall’s error.
Sourcepub fn finish(self) -> SHA256Hash
pub fn finish(self) -> SHA256Hash
Consume the hasher and return the SHA256 hash of the prior input, freeing its VM-side stream.
Throws a syscall exception (aborting the frame) if the host call fails.