39 releases

0.19.3 Dec 6, 2024
0.19.2 Oct 24, 2024
0.19.1 Sep 7, 2023
0.19.0 Jun 6, 2023
0.1.0 Dec 28, 2015

#77 in Encoding

Download history 201973/week @ 2024-08-29 222765/week @ 2024-09-05 214976/week @ 2024-09-12 236009/week @ 2024-09-19 228271/week @ 2024-09-26 262142/week @ 2024-10-03 246871/week @ 2024-10-10 256719/week @ 2024-10-17 263513/week @ 2024-10-24 266972/week @ 2024-10-31 242151/week @ 2024-11-07 241384/week @ 2024-11-14 269402/week @ 2024-11-21 240041/week @ 2024-11-28 289105/week @ 2024-12-05 238361/week @ 2024-12-12

1,079,546 downloads per month
Used in 1,127 crates (129 directly)

MIT license

34KB
602 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.

MSRV

The minimum supported Rust version for this library is 1.64.0. This is only guaranteed without additional features activated.

Usage

The multihash crate exposes a basic data structure for encoding and decoding multihash. It does not provide any hashing functionality itself. Multihash uses const-generics to define the internal buffer size. You should set this to the maximum size of the digest you want to support.

use multihash::Multihash;

const SHA2_256: u64 = 0x12;

fn main() {
	let hash = Multihash::<64>::wrap(SHA2_256, b"my digest");
	println!("{:?}", hash);
}

Using a custom code table

You can derive your own application specific code table using the multihash-derive crate. The multihash-codetable provides predefined hasher implementations if you don't want to implement your own.

use multihash_derive::MultihashDigest;

#[derive(Clone, Copy, Debug, Eq, MultihashDigest, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
    #[mh(code = 0x01, hasher = multihash_codetable::Sha2_256)]
    Foo,
    #[mh(code = 0x02, hasher = multihash_codetable::Sha2_512)]
    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.3–1MB
~18K SLoC