Trait sc_network::multiaddr::multihash::MultihashDigest
source · pub trait MultihashDigest<const S: usize>: TryFrom<u64> + Into<u64> + Send + Sync + Unpin + Copy + Eq + Debug + 'static {
// Required methods
fn digest(&self, input: &[u8]) -> Multihash<S>;
fn wrap(&self, digest: &[u8]) -> Result<Multihash<S>, Error>;
}
Expand description
Trait that implements hashing.
It is usually implemented by a custom code table enum that derives the Multihash
derive.
Required Methods§
sourcefn digest(&self, input: &[u8]) -> Multihash<S>
fn digest(&self, input: &[u8]) -> Multihash<S>
Calculate the hash of some input data.
Example
// `Code` implements `MultihashDigest`
use multihash::{Code, MultihashDigest};
let hash = Code::Sha3_256.digest(b"Hello world!");
println!("{:02x?}", hash);
sourcefn wrap(&self, digest: &[u8]) -> Result<Multihash<S>, Error>
fn wrap(&self, digest: &[u8]) -> Result<Multihash<S>, Error>
Create a multihash from an existing multihash digest.
Example
use multihash::{Code, Hasher, MultihashDigest, Sha3_256};
let mut hasher = Sha3_256::default();
hasher.update(b"Hello world!");
let hash = Code::Sha3_256.wrap(&hasher.finalize()).unwrap();
println!("{:02x?}", hash);