multihash implementation in Rust.
First add this to your Cargo.toml
[dependencies]
multihash = "*"
Then run cargo build
.
MSRV 1.51.0 due to use of const generics
use multihash::{Code, MultihashDigest};
fn main() {
let hash = Code::Sha2_256.digest(b"my hash");
println!("{:?}", hash);
}
You can derive your own application specific code table:
use multihash::derive::Multihash;
use multihash::MultihashCode;
#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
#[mh(code = 0x01, hasher = multihash::Sha2_256)]
Foo,
#[mh(code = 0x02, hasher = multihash::Sha2_512)]
Bar,
}
fn main() {
let hash = Code::Foo.digest(b"my hash");
println!("{:02x?}", hash);
}
SHA1
SHA2-256
SHA2-512
SHA3
/Keccak
Blake2b-256
/Blake2b-512
/Blake2s-128
/Blake2s-256
Blake3
Strobe
Captain: @dignifiedquire.
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.