pub struct Hash { /* private fields */ }Implementations§
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.