use super::DigestPrimitive;
use hybrid_array::{
Array,
typenum::{U32, U48, U64},
};
use sha2::Digest as _;
#[derive(Debug, Clone, Copy)]
pub enum Sha256 {}
impl DigestPrimitive for Sha256 {
type Size = U32;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha2::Sha256::digest(data);
Array::try_from(result.as_slice()).expect("sha256 output is always 32 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Sha384 {}
impl DigestPrimitive for Sha384 {
type Size = U48;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha2::Sha384::digest(data);
Array::try_from(result.as_slice()).expect("sha384 output is always 48 bytes")
}
}
#[derive(Debug, Clone, Copy)]
pub enum Sha512 {}
impl DigestPrimitive for Sha512 {
type Size = U64;
#[allow(clippy::expect_used)] fn hash(data: &[u8]) -> Array<u8, Self::Size> {
let result = sha2::Sha512::digest(data);
Array::try_from(result.as_slice()).expect("sha512 output is always 64 bytes")
}
}