pub struct Hash { /* private fields */ }Implementations§
Source§impl Hash
impl Hash
Sourcepub fn display_base64(&self) -> impl Display
pub fn display_base64(&self) -> impl Display
Returns an adapter that renders the unpadded base64url representation
via core::fmt::Display.
The adapter streams directly into the formatter without allocating,
and produces exactly the same text as Hash::to_base64.
Source§impl Hash
impl Hash
Sourcepub fn from_parts(
digest: &[u8; 32],
data_len: PackedInt,
) -> Result<Hash, HashError>
pub fn from_parts( digest: &[u8; 32], data_len: PackedInt, ) -> Result<Hash, HashError>
Reconstructs a hash from its stored parts: the digest and the packed data length.
The parity block is a deterministic function of the parts, so storage that holds many hashes may keep only the digest and length field and rebuild the full hash on demand.
§Errors
HashError::ZeroDigestifdigestis all zeros. No hashed input produces the zero digest, andHash::validaterejects it, so a hash built from it could never be validated.HashError::RSGenerateParityErrorif parity generation fails.
Source§impl Hash
impl Hash
Sourcepub fn to_crockford(&self) -> String
pub fn to_crockford(&self) -> String
Returns the Crockford Base32 representation.
The alphabet is case-insensitive on input and excludes the ambiguous
glyphs I, L, O, and U, which makes it the better choice for
hashes that are read, spoken, or typed by hand.
Source§impl Hash
impl Hash
Sourcepub fn validate(bytes: impl AsRef<[u8]>) -> Result<Hash, HashValidationError>
pub fn validate(bytes: impl AsRef<[u8]>) -> Result<Hash, HashValidationError>
Validates and, where necessary, repairs a hash in any of its representations.
The representation is selected by input length, since the three accepted ranges are disjoint:
| length | representation |
|---|---|
| 41..=48 | binary, including compact |
| 55..=64 | base64url |
| 66..=77 | Crockford Base32 |
Inputs shorter than the full size are treated as truncated and are
restored by the Reed-Solomon codec, which corrects up to
PARITY byte errors.
§Errors
HashValidationError::InvalidLengthif the length matches no representation.HashValidationError::RSDecodeErrorif the damage exceeds what the Reed-Solomon codec can correct.HashValidationError::ZeroDigestif the corrected digest is all zeros. No hashed input produces the zero digest, but the all-zero buffer is a valid Reed-Solomon codeword, so it must be rejected explicitly.
Source§impl Hash
impl Hash
pub fn validate_bin_vec(hash: &mut Vec<u8>) -> Result<Hash, HashValidationError>
Trait Implementations§
impl Copy for Hash
impl Eq for Hash
Source§impl Ord for Hash
impl Ord for Hash
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Hash
impl PartialOrd for Hash
Auto Trait Implementations§
impl Freeze for Hash
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnsafeUnpin for Hash
impl UnwindSafe for Hash
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T> MbufValue for Twhere
T: Copy,
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.