#multi-hash #codec #hashing #decoding #secure #data #ipfs

no-std multihash-codetable

Default multihash code-table with cryptographically secure hash implementations

3 releases

0.1.2 Feb 23, 2024
0.1.1 Oct 30, 2023
0.1.0 Jun 6, 2023

#380 in Cryptography

Download history 7511/week @ 2023-12-23 11530/week @ 2023-12-30 17064/week @ 2024-01-06 22421/week @ 2024-01-13 22582/week @ 2024-01-20 21165/week @ 2024-01-27 20680/week @ 2024-02-03 21996/week @ 2024-02-10 31355/week @ 2024-02-17 27538/week @ 2024-02-24 20505/week @ 2024-03-02 23747/week @ 2024-03-09 24540/week @ 2024-03-16 24995/week @ 2024-03-23 36017/week @ 2024-03-30 29935/week @ 2024-04-06

119,578 downloads per month
Used in 61 crates (5 directly)

MIT license

28KB
440 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


lib.rs:

A batteries-included code table of multihashes.

Whilst the multihash crate itself only defines the data structure, this crate defines a codetable via multihash_derive for several hashers. Although convenient, depending on this crate will increase the dependency footprint of your project.

It is only recommended as a getting-started-quickly solution. For production, you should either define your own codetable or rely only on the multihash crate itself.

Dependencies

~3.5–5MB
~99K SLoC