use crate::Shake128State;
use core::hash::Hasher;
use rs_hasher_ctx::{ByteArrayWrapper, GenericHasher, HasherContext};
use rs_internal_hasher::HashAlgorithm;
use rs_internal_state::ExtendedOutputFunction;
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct Shake128Hasher<const OUTPUT_SIZE: usize>(GenericHasher<Shake128State<OUTPUT_SIZE>, OUTPUT_SIZE>);
impl<const OUTPUT_SIZE: usize> From<Shake128Hasher<OUTPUT_SIZE>> for Shake128State<OUTPUT_SIZE> {
fn from(value: Shake128Hasher<OUTPUT_SIZE>) -> Self {
value.0.state
}
}
impl<const OUTPUT_SIZE: usize> From<Shake128State<OUTPUT_SIZE>> for Shake128Hasher<OUTPUT_SIZE> {
fn from(value: Shake128State<OUTPUT_SIZE>) -> Self {
Self(GenericHasher {
padding: <Shake128State<OUTPUT_SIZE> as HashAlgorithm>::Padding::default(),
state: value,
})
}
}
impl<const OUTPUT_SIZE: usize> Hasher for Shake128Hasher<OUTPUT_SIZE> {
fn finish(&self) -> u64 {
Hasher::finish(&self.0)
}
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
}
}
impl<const OUTPUT_SIZE: usize> HasherContext<OUTPUT_SIZE> for Shake128Hasher<OUTPUT_SIZE> {
type Output = ByteArrayWrapper<OUTPUT_SIZE>;
fn finish(&mut self) -> Self::Output {
ByteArrayWrapper::from(HasherContext::finish(&mut self.0).squeeze())
}
}