#![no_std]
extern crate generic_array;
use generic_array::{GenericArray, ArrayLength};
pub trait DigestInput {
type BlockSize: ArrayLength<u8>;
fn digest(&mut self, input: &[u8]);
}
pub trait DigestFixedOutput {
type OutputSize: ArrayLength<u8>;
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>;
}
pub struct InvalidLength;
pub trait DigestVariableOutput {
fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength>;
}
pub trait Digest: DigestInput + DigestFixedOutput {
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: DigestInput + DigestFixedOutput> Digest for T {
type OutputSize = <T as DigestFixedOutput>::OutputSize;
type BlockSize = <T as DigestInput>::BlockSize;
fn input(&mut self, input: &[u8]) {
self.digest(input);
}
fn result(self) -> GenericArray<u8, <T as Digest>::OutputSize> {
self.fixed_result()
}
}