Trait otter_nodejs_tests::otter_support::crates::digest::VariableOutput
source · [−]pub trait VariableOutput: Update {
const MAX_OUTPUT_SIZE: usize;
fn new(output_size: usize) -> Result<Self, InvalidOutputSize>;
fn output_size(&self) -> usize;
fn finalize_variable(self, out: &mut [u8]) -> Result<(), InvalidBufferSize>;
fn digest_variable(
input: impl AsRef<[u8]>,
output: &mut [u8]
) -> Result<(), InvalidOutputSize> { ... }
fn finalize_boxed(self) -> Box<[u8], Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
{ ... }
}
Expand description
Trait for hash functions with variable-size output.
Required Associated Constants
const MAX_OUTPUT_SIZE: usize
const MAX_OUTPUT_SIZE: usize
Maximum size of output hash.
Required Methods
fn new(output_size: usize) -> Result<Self, InvalidOutputSize>
fn new(output_size: usize) -> Result<Self, InvalidOutputSize>
Create new hasher instance with the given output size.
It will return Err(InvalidOutputSize)
in case if hasher can not return
hash of the specified output size.
fn output_size(&self) -> usize
fn output_size(&self) -> usize
Get output size of the hasher instance provided to the new
method
fn finalize_variable(self, out: &mut [u8]) -> Result<(), InvalidBufferSize>
fn finalize_variable(self, out: &mut [u8]) -> Result<(), InvalidBufferSize>
Write result into the output buffer.
Returns Err(InvalidOutputSize)
if out
size is not equal to
self.output_size()
.
Provided Methods
fn digest_variable(
input: impl AsRef<[u8]>,
output: &mut [u8]
) -> Result<(), InvalidOutputSize>
fn digest_variable(
input: impl AsRef<[u8]>,
output: &mut [u8]
) -> Result<(), InvalidOutputSize>
Compute hash of data
and write it to output
.
Length of the output hash is determined by output
. If output
is
bigger than Self::MAX_OUTPUT_SIZE
, this method returns
InvalidOutputSize
.
fn finalize_boxed(self) -> Box<[u8], Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn finalize_boxed(self) -> Box<[u8], Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
Retrieve result into a boxed slice and consume hasher.
Box<[u8]>
is used instead of Vec<u8>
to save stack space, since
they have size of 2 and 3 words respectively.