pub trait HashOption: ::std::default::Default {}
pub enum HashError {
GenericError,
}
pub trait HashAlgoKernel {
type Option: HashOption;
type Error: ::std::convert::Into<HashError> + ::std::fmt::Debug;
type Output: ::std::cmp::Eq
+ ::std::convert::AsRef<[u8]>
+ ::std::fmt::LowerHex
+ ::std::fmt::UpperHex;
fn name() -> &'static str;
fn digest_size() -> usize;
fn new(opt: Self::Option) -> Self;
fn update<T>(&mut self, data: T) -> Result<(), Self::Error>
where
T: ::std::convert::AsRef<[u8]>;
fn finalize(self) -> Result<Self::Output, Self::Error>;
}
pub trait HashAlgo: ::std::default::Default {
type Kernel: HashAlgoKernel;
fn setup() -> <<Self as HashAlgo>::Kernel as HashAlgoKernel>::Option {
::std::default::Default::default()
}
fn hash(
input: &[u8],
) -> Result<
<<Self as HashAlgo>::Kernel as HashAlgoKernel>::Output,
<<Self as HashAlgo>::Kernel as HashAlgoKernel>::Error,
> {
let opt = Self::setup();
let mut algo = Self::Kernel::new(opt);
algo.update(input)?;
algo.finalize()
}
}