use super::DigestPrimitive;
use hybrid_array::{
Array,
typenum::{U28, U32, U48, U64},
};
use sha3::Digest as _;
#[derive(Debug, Clone, Copy)]
pub enum Sha3_224 {}
impl DigestPrimitive for Sha3_224 {
type Size = U28;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Sha3_224::digest(data);
Array::try_from(result.as_slice()).expect("sha3-224 output is always 28 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Sha3_256 {}
impl DigestPrimitive for Sha3_256 {
type Size = U32;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Sha3_256::digest(data);
Array::try_from(result.as_slice()).expect("sha3-256 output is always 32 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Sha3_384 {}
impl DigestPrimitive for Sha3_384 {
type Size = U48;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Sha3_384::digest(data);
Array::try_from(result.as_slice()).expect("sha3-384 output is always 48 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Sha3_512 {}
impl DigestPrimitive for Sha3_512 {
type Size = U64;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Sha3_512::digest(data);
Array::try_from(result.as_slice()).expect("sha3-512 output is always 64 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Keccak256 {}
impl DigestPrimitive for Keccak256 {
type Size = U32;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Keccak256::digest(data);
Array::try_from(result.as_slice()).expect("keccak256 output is always 32 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Keccak512 {}
impl DigestPrimitive for Keccak512 {
type Size = U64;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha3::Keccak512::digest(data);
Array::try_from(result.as_slice()).expect("keccak512 output is always 64 bytes")
}
}