const LEN: usize = <Inner as hashes::Hash>::LEN;
#[cfg(feature = "hex")]
const REVERSE: bool = <Inner as hashes::Hash>::DISPLAY_BACKWARD;
impl HashType {
pub const fn from_byte_array(bytes: [u8; LEN]) -> Self {
Self(Inner::from_byte_array(bytes))
}
pub const fn to_byte_array(self) -> [u8; LEN] { self.0.to_byte_array() }
pub const fn as_byte_array(&self) -> &[u8; LEN] { self.0.as_byte_array() }
}
#[cfg(feature = "serde")]
super::impl_serde!(HashType, LEN);
super::impl_bytelike_traits!(HashType, LEN);
#[cfg(feature = "hex")]
impl fmt::LowerHex for HashType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
}
#[cfg(feature = "hex")]
impl fmt::UpperHex for HashType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) }
}
#[cfg(feature = "hex")]
impl fmt::Display for HashType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
}
#[cfg(feature = "hex")]
impl str::FromStr for HashType {
type Err = hex::DecodeFixedLengthBytesError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut bytes = crate::hex::decode_to_array(s)?;
if REVERSE {
bytes.reverse();
}
Ok(Self::from_byte_array(bytes))
}
}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for HashType {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let arbitrary_bytes = u.arbitrary()?;
Ok(Self::from_byte_array(arbitrary_bytes))
}
}