#![cfg_attr(not(feature = "std"), no_std)]
extern crate generic_array;
use generic_array::{GenericArray, ArrayLength};
mod digest;
pub use digest::Digest;
pub trait Input {
fn process(&mut self, input: &[u8]);
}
pub trait BlockInput {
type BlockSize: ArrayLength<u8>;
}
pub trait FixedOutput {
type OutputSize: ArrayLength<u8>;
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>;
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct InvalidLength;
pub trait VariableOutput {
fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength>;
}
pub trait XofReader: core::marker::Sized {
fn read(&mut self, buffer: &mut [u8]);
}
pub trait ExtendableOutput {
type Reader: XofReader;
fn xof_result(self) -> Self::Reader;
}
impl<D: ExtendableOutput> VariableOutput for D {
fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength> {
let mut reader = self.xof_result();
reader.read(buffer);
Ok(buffer)
}
}