https://github.com/multiformats/rust-multihash
multihash implementation in Rust
https://github.com/multiformats/rust-multihash
hash hash-algorithm ipfs multiformats rust
Last synced: 18 days ago
JSON representation
multihash implementation in Rust
- Host: GitHub
- URL: https://github.com/multiformats/rust-multihash
- Owner: multiformats
- License: other
- Created: 2015-12-28T14:06:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-04-28T23:39:00.000Z (about 1 month ago)
- Last Synced: 2025-04-29T00:38:27.057Z (about 1 month ago)
- Topics: hash, hash-algorithm, ipfs, multiformats, rust
- Language: Rust
- Homepage: https://github.com/multiformats/multihash
- Size: 2.73 MB
- Stars: 161
- Watchers: 13
- Forks: 63
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - multiformats/rust-multihash - multihash implementation in Rust (ipfs)
README
# rust-multihash
[](http://ipn.io)
[](https://github.com/multiformats/multiformats)
[](https://webchat.freenode.net/?channels=%23ipfs)
[](https://github.com/RichardLitt/standard-readme)[](https://github.com/multiformats/rust-multihash/actions)
[](https://crates.io/crates/multihash)
[](LICENSE)
[](https://docs.rs/multihash)
[](https://deps.rs/repo/github/multiformats/rust-multihash)
[](https://codecov.io/gh/multiformats/rust-multihash)> [multihash](https://github.com/multiformats/multihash) implementation in Rust.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Supported Hash Types](#supported-hash-types)
- [Maintainers](#maintainers)
- [Contribute](#contribute)
- [License](#license)## Install
First add this to your `Cargo.toml`
```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.```rust
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.```rust
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](https://github.com/dignifiedquire).
## Contribute
Contributions welcome. Please check out [the issues](https://github.com/multiformats/rust-multihash/issues).
Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) 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](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
[MIT](LICENSE)