#[cfg(not(feature = "sha256"))]
pub(crate) const HASH_ALGORITHM: &str = "blake3";
#[cfg(feature = "sha256")]
pub(crate) const HASH_ALGORITHM: &str = "sha256";
pub(crate) struct ChainHasher {
#[cfg(not(feature = "sha256"))]
inner: blake3::Hasher,
#[cfg(feature = "sha256")]
inner: sha2::Sha256,
}
impl ChainHasher {
#[inline]
pub fn new() -> Self {
Self {
#[cfg(not(feature = "sha256"))]
inner: blake3::Hasher::new(),
#[cfg(feature = "sha256")]
inner: <sha2::Sha256 as sha2::Digest>::new(),
}
}
#[inline]
pub fn update(&mut self, data: &[u8]) {
#[cfg(not(feature = "sha256"))]
{
self.inner.update(data);
}
#[cfg(feature = "sha256")]
{
<sha2::Sha256 as sha2::Digest>::update(&mut self.inner, data);
}
}
#[inline]
pub fn finalize_hex(self) -> String {
#[cfg(not(feature = "sha256"))]
{
self.inner.finalize().to_hex().to_string()
}
#[cfg(feature = "sha256")]
{
format!("{:x}", <sha2::Sha256 as sha2::Digest>::finalize(self.inner))
}
}
}