pub struct Multihash(/* private fields */);Expand description
A content hash tagged with its algorithm code.
Internally wraps multihash::Multihash<64> - 64 bytes of buffer, enough
for any algorithm on mnem’s allow-list (SHA-256, BLAKE3-256 today;
SHA-512, BLAKE3-512, etc. if later expanded).
§Equality
Two Multihash values are equal only if they have the same algorithm
code AND the same digest bytes. A SHA-256 and a BLAKE3-256 of the same
input never compare equal even if their digest bytes collide.
Implementations§
Source§impl Multihash
impl Multihash
Sourcepub fn sha2_256(bytes: &[u8]) -> Self
pub fn sha2_256(bytes: &[u8]) -> Self
Compute a SHA-256 multihash of bytes.
This is the default content-hash algorithm for mnem/0.1.
Sourcepub fn blake3_256(bytes: &[u8]) -> Self
pub fn blake3_256(bytes: &[u8]) -> Self
Compute a BLAKE3-256 multihash of bytes.
Produces a 32-byte digest with algorithm code 0x1e. Faster than
SHA-256 in most conditions; accepted by mnem but not the default
for mnem/0.1 .
Sourcepub fn wrap(code: u64, digest: &[u8]) -> Result<Self, IdError>
pub fn wrap(code: u64, digest: &[u8]) -> Result<Self, IdError>
Wrap a raw algorithm code + digest bytes into a Multihash.
§Errors
Returns IdError::Multihash if digest.len() > 64 or if the
digest length is otherwise invalid for the declared code.
Sourcepub const fn code(&self) -> u64
pub const fn code(&self) -> u64
The algorithm code byte. See HASH_SHA2_256 and friends.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to the multihash wire format: <code: varint> <size: varint> <digest>.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, IdError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, IdError>
Parse a multihash from its wire format.
§Errors
Returns IdError::Multihash if the bytes are malformed.