digest

Trait VariableOutput

Source
pub trait VariableOutput: Sized + Update {
    const MAX_OUTPUT_SIZE: usize;

    // Required methods
    fn new(output_size: usize) -> Result<Self, InvalidOutputSize>;
    fn output_size(&self) -> usize;
    fn finalize_variable(self, out: &mut [u8]) -> Result<(), InvalidBufferSize>;

    // Provided methods
    fn digest_variable(
        input: impl AsRef<[u8]>,
        output: &mut [u8],
    ) -> Result<(), InvalidOutputSize> { ... }
    fn finalize_boxed(self) -> Box<[u8]> { ... }
}
Expand description

Trait for hash functions with variable-size output.

Required Associated Constants§

Source

const MAX_OUTPUT_SIZE: usize

Maximum size of output hash.

Required Methods§

Source

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.

Source

fn output_size(&self) -> usize

Get output size of the hasher instance provided to the new method

Source

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§

Source

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.

Source

fn finalize_boxed(self) -> Box<[u8]>

Available on crate feature alloc only.

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> VariableOutput for RtVariableCoreWrapper<T>

Available on crate feature core-api only.
Source§

const MAX_OUTPUT_SIZE: usize = <T::OutputSize>::USIZE