27 releases

0.14.0 May 26, 2021
0.13.2 Dec 1, 2020
0.13.1 Nov 16, 2020
0.11.2 May 19, 2020
0.1.0 Dec 28, 2015

#71 in Algorithms

Download history 18587/week @ 2021-06-06 17271/week @ 2021-06-13 14849/week @ 2021-06-20 14462/week @ 2021-06-27 19650/week @ 2021-07-04 17805/week @ 2021-07-11 17411/week @ 2021-07-18 16852/week @ 2021-07-25 20645/week @ 2021-08-01 16401/week @ 2021-08-08 19814/week @ 2021-08-15 25243/week @ 2021-08-22 25342/week @ 2021-08-29 25074/week @ 2021-09-05 30753/week @ 2021-09-12 28266/week @ 2021-09-19

65,111 downloads per month
Used in 392 crates (60 directly)

MIT license

45KB
813 lines

rust-multihash

Build Status Crates.io License Documentation Dependency Status Coverage Status

multihash implementation in Rust.

Table of Contents

Install

First add this to your Cargo.toml

[dependencies]
multihash = "*"

Then run cargo build.

Usage

use multihash::{Code, MultihashDigest};

fn main() {
    let hash = Code::Sha2_256.digest(b"my hash");
    println!("{:?}", hash);
}

Using a custom code table

You can derive your own application specific code table:

use multihash::derive::Multihash;
use multihash::{MultihashDigest, U32, U64};

#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
#[mh(alloc_size = U64)]
pub enum Code {
    #[mh(code = 0x01, hasher = multihash::Sha2_256, digest = multihash::Sha2Digest<U32>)]
    Foo,
    #[mh(code = 0x02, hasher = multihash::Sha2_512, digest = multihash::Sha2Digest<U64>)]
    Bar,
}

fn main() {
    let hash = Code::Foo.digest(b"my hash");
    println!("{:02x?}", hash);
}

Supported Hash Types

  • SHA1
  • SHA2-256
  • SHA2-512
  • SHA3/Keccak
  • Blake2b-256/Blake2b-512/Blake2s-128/Blake2s-256
  • Blake3
  • Strobe

Maintainers

Captain: @dignifiedquire.

Contribute

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.

License

MIT

Dependencies

~0.2–1.3MB
~28K SLoC