[−]Trait ipfs_embed_core::MultihashCode
Trait that implements hashing.
It is usually implemented by a custom code table enum that derives the Multihash
derive.
Associated Types
type AllocSize: Size
The maximum size a hash will allocate.
Required methods
pub fn digest(&self, input: &[u8]) -> Multihash<Self::AllocSize>
Calculate the hash of some input data.
Example
// `Code` implements `MultihashCode` use tiny_multihash::{Code, MultihashCode}; let hash = Code::Sha3_256.digest(b"Hello world!"); println!("{:02x?}", hash);
pub fn multihash_from_digest<'a, S, D>(
digest: &'a D
) -> Multihash<Self::AllocSize> where
D: Digest<S>,
S: Size,
Self: From<&'a D>,
digest: &'a D
) -> Multihash<Self::AllocSize> where
D: Digest<S>,
S: Size,
Self: From<&'a D>,
Create a multihash from an existing [Digest
].
Example
use tiny_multihash::{Code, MultihashCode, Sha3_256, StatefulHasher}; let mut hasher = Sha3_256::default(); hasher.update(b"Hello world!"); let hash = Code::multihash_from_digest(&hasher.finalize()); println!("{:02x?}", hash);
Implementations on Foreign Types
impl MultihashCode for Code
type AllocSize = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>
pub fn digest(
&self,
input: &[u8]
) -> Multihash<<Code as MultihashCode>::AllocSize>
&self,
input: &[u8]
) -> Multihash<<Code as MultihashCode>::AllocSize>
pub fn multihash_from_digest<'a, S, D>(
digest: &'a D
) -> Multihash<<Code as MultihashCode>::AllocSize> where
D: Digest<S>,
S: Size,
Code: From<&'a D>,
digest: &'a D
) -> Multihash<<Code as MultihashCode>::AllocSize> where
D: Digest<S>,
S: Size,
Code: From<&'a D>,