#multihash #ipfs

tiny-multihash

Implementation of the multihash format

12 releases (4 breaking)

0.5.0 Oct 1, 2020
0.4.8 Oct 1, 2020
0.4.7 Sep 18, 2020
0.4.5 Aug 30, 2020
0.1.0 Jun 18, 2020

#14 in #multihash

Download history 151/week @ 2021-07-04 79/week @ 2021-07-11 115/week @ 2021-07-18 61/week @ 2021-07-25 87/week @ 2021-08-01 60/week @ 2021-08-08 83/week @ 2021-08-15 52/week @ 2021-08-22 28/week @ 2021-08-29 7/week @ 2021-09-05 25/week @ 2021-09-12 35/week @ 2021-09-19 141/week @ 2021-09-26 34/week @ 2021-10-03 135/week @ 2021-10-10 263/week @ 2021-10-17

462 downloads per month
Used in 7 crates (via tiny-cid)

MIT license

47KB
933 lines

tiny-multihash

Crates.io Documentation

multihash implementation in Rust.

Table of Contents

Install

First add this to your Cargo.toml

[dependencies]
tiny-multihash = "*"

Then run cargo build.

Usage

use tiny_multihash::{Multihash, MultihashDigest, SHA2_256};

fn main() {
    let hash = Multihash::new(SHA2_256, b"my hash");
    println!("{:?}", hash);
}

Using a custom code table

You can derive your own application specific code table:

use tiny_multihash::derive::Multihash;
use tiny_multihash::{Hasher, MultihashDigest};

const FOO: u64 = 0x01;
const BAR: u64 = 0x02;

#[derive(Clone, Debug, Eq, Multihash, PartialEq)]
pub enum Multihash {
    #[mh(code = FOO, hasher = tiny_multihash::Sha2_256)]
    Foo(tiny_multihash::Sha2Digest<tiny_multihash::U32>),
    #[mh(code = BAR, hasher = tiny_multihash::Sha2_512)]
    Bar(tiny_multihash::Sha2Digest<tiny_multihash::U64>),
}

fn main() {
    let hash = Multihash::new(FOO, b"my hash");
    println!("{:?}", hash);
}

Supported Hash Types

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

Maintainers

@dvc94ch

Dependencies

~0.2–1.3MB
~28K SLoC

v_