28 releases

0.15.0 Oct 4, 2021
0.14.0 May 26, 2021
0.13.2 Dec 1, 2020
0.13.1 Nov 16, 2020
0.1.0 Dec 28, 2015

#150 in Algorithms

Download history 30731/week @ 2021-09-26 29923/week @ 2021-10-03 33061/week @ 2021-10-10 30613/week @ 2021-10-17 27400/week @ 2021-10-24 31292/week @ 2021-10-31 31231/week @ 2021-11-07 29184/week @ 2021-11-14 31152/week @ 2021-11-21 33426/week @ 2021-11-28 33030/week @ 2021-12-05 30757/week @ 2021-12-12 22202/week @ 2021-12-19 15478/week @ 2021-12-26 22571/week @ 2022-01-02 28081/week @ 2022-01-09

90,527 downloads per month
Used in 402 crates (59 directly)

MIT license

47KB
837 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.2MB
~27K SLoC