Struct Hash

struct Hash(_)

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 from_bytes and as_bytes for explicit conversions between itself and [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

impl Hash

const fn as_bytes(self: &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.

const fn from_bytes(bytes: [u8; 32]) -> Self

Create a Hash from its raw bytes representation.

fn to_hex(self: &Self) -> ArrayString<{ _ }>

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.

fn from_hex<impl AsRef<[u8]>: AsRef<[u8]>>(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().

impl Clone for Hash

fn clone(self: &Self) -> Hash

impl Copy for Hash

impl Debug for Hash

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Display for Hash

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Eq for Hash

impl Freeze for Hash

impl From for Hash

fn from(bytes: [u8; 32]) -> Self

impl FromStr for Hash

fn from_str(s: &str) -> Result<Self, <Self as >::Err>

impl Hash for Hash

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl PartialEq for Hash

fn eq(self: &Self, other: &[u8]) -> bool

impl PartialEq for Hash

fn eq(self: &Self, other: &Hash) -> bool

impl PartialEq for Hash

fn eq(self: &Self, other: &[u8; 32]) -> bool

impl RefUnwindSafe for Hash

impl Send for Hash

impl Sync for Hash

impl Unpin for Hash

impl UnwindSafe for Hash

impl<T> Any for Hash

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Hash

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Hash

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Hash

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Hash

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Hash

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for Hash

fn to_string(self: &Self) -> String

impl<T, U> Into for Hash

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Hash

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Hash

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>