#![no_std]
extern crate generic_array;
use generic_array::{GenericArray, ArrayLength};
pub trait Input {
type BlockSize: ArrayLength<u8>;
fn digest(&mut self, input: &[u8]);
}
pub trait FixedOutput {
type OutputSize: ArrayLength<u8>;
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>;
}
#[derive(Copy, Clone, Debug)]
pub struct InvalidLength;
#[must_use]
pub type VariableResult<'a> = Result<&'a [u8], InvalidLength>;
pub trait VariableOutput {
fn variable_result(self, buffer: &mut [u8]) -> VariableResult;
}
pub trait Digest: Input + FixedOutput {
type OutputSize: ArrayLength<u8>;
type BlockSize: ArrayLength<u8>;
fn input(&mut self, input: &[u8]);
fn result(self) -> GenericArray<u8, <Self as Digest>::OutputSize>;
}
impl<T: Input + FixedOutput> Digest for T {
type OutputSize = <T as FixedOutput>::OutputSize;
type BlockSize = <T as Input>::BlockSize;
fn input(&mut self, input: &[u8]) {
self.digest(input);
}
fn result(self) -> GenericArray<u8, <T as Digest>::OutputSize> {
self.fixed_result()
}
}