diff --git a/hashes/src/siphash24.rs b/hashes/src/siphash24.rs index d0258a06c..6aaed346a 100644 --- a/hashes/src/siphash24.rs +++ b/hashes/src/siphash24.rs @@ -4,8 +4,11 @@ use core::ops::Index; use core::slice::SliceIndex; +use core::str::FromStr; use core::{cmp, mem, ptr}; +use hex::FromHex; + use crate::internal_macros::arr_newtype_fmt_impl; use crate::HashEngine as _; @@ -264,7 +267,16 @@ impl> Index for Hash { fn index(&self, index: I) -> &Self::Output { &self.0[index] } } +impl FromStr for Hash { + type Err = hex::HexToArrayError; + fn from_str(s: &str) -> Result { + let bytes = <[u8; 8]>::from_hex(s)?; + Ok(Self::from_byte_array(bytes)) + } +} + arr_newtype_fmt_impl!(Hash, 8); +serde_impl!(Hash, 8); borrow_slice_impl!(Hash); /// Load an u64 using up to 7 bytes of a byte slice.