use crate::{crypto::dummy_crypto_call, misc::DefaultArray};
use core::marker::PhantomData;
#[cfg(feature = "crypto-aws-lc-rs")]
mod aws_lc_rs;
pub(crate) mod global;
#[cfg(feature = "crypto-graviola")]
mod graviola;
#[cfg(feature = "crypto-ring")]
mod ring;
#[cfg(feature = "crypto-ruco")]
mod ruco;
pub trait Hash: Sized {
type Digest: AsRef<[u8]>;
#[inline]
fn digest<'data>(data: impl IntoIterator<Item = &'data [u8]>) -> Self::Digest {
let mut ctx = Self::new();
for elem in data {
ctx.update(elem);
}
ctx.finalize()
}
fn new() -> Self;
fn finalize(self) -> Self::Digest;
fn update(&mut self, data: &[u8]);
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct HashDummy<D>(PhantomData<D>);
impl<D> Hash for HashDummy<D>
where
D: AsRef<[u8]> + DefaultArray,
{
type Digest = D;
#[inline]
fn new() -> Self {
HashDummy(PhantomData)
}
#[inline]
fn finalize(self) -> Self::Digest {
dummy_crypto_call();
}
#[inline]
fn update(&mut self, _: &[u8]) {}
}