pub struct Hash(_);
Expand description
An output of the default size, 32 bytes, which provides constant-time equality checking.
Hash
implements From
and Into
for [u8; 32]
, and it provides an
explicit as_bytes
method returning &[u8; 32]
. However, byte arrays
and slices don’t provide constant-time equality checking, which is often a
security requirement in software that handles private data. Hash
doesn’t
implement Deref
or AsRef
, to avoid situations where a type
conversion happens implicitly and the constant-time property is
accidentally lost.
Hash
provides the to_hex
and from_hex
methods for converting to
and from hexadecimal. It also implements Display
and FromStr
.
Implementations
sourceimpl Hash
impl Hash
sourcepub fn as_bytes(&self) -> &[u8; 32]
pub fn as_bytes(&self) -> &[u8; 32]
The raw bytes of the Hash
. Note that byte arrays don’t provide
constant-time equality checking, so if you need to compare hashes,
prefer the Hash
type.
sourcepub fn to_hex(&self) -> ArrayString<{ 2 * OUT_LEN }>
pub fn to_hex(&self) -> ArrayString<{ 2 * OUT_LEN }>
Encode a Hash
in lowercase hexadecimal.
The returned ArrayString
is a fixed size and doesn’t allocate memory
on the heap. Note that ArrayString
doesn’t provide constant-time
equality checking, so if you need to compare hashes, prefer the Hash
type.
sourcepub fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, HexError>
pub fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, HexError>
Decode a Hash
from hexadecimal. Both uppercase and lowercase ASCII
bytes are supported.
Any byte outside the ranges '0'...'9'
, 'a'...'f'
, and 'A'...'F'
results in an error. An input length other than 64 also results in an
error.
Note that Hash
also implements FromStr
, so Hash::from_hex("...")
is equivalent to "...".parse()
.
Trait Implementations
sourceimpl PartialEq<[u8]> for Hash
impl PartialEq<[u8]> for Hash
This implementation is constant-time if the target is 32 bytes long.
impl Copy for Hash
impl Eq for Hash
Auto Trait Implementations
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnwindSafe for Hash
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more