Skip to content

Commit

Permalink
fix README, add license tags
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Huseby <[email protected]>
  • Loading branch information
dhuseby committed Apr 7, 2024
1 parent fbc9db7 commit 325657d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![](https://img.shields.io/badge/made%20by-Cryptid%20Technologies-gold.svg?style=flat-square)][CRYPTID]
[![](https://img.shields.io/badge/project-provenance-purple.svg?style=flat-square)][PROVENANCE]
[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)][MULTIFORMATS]
![](https://github.com/cryptidtech/multihash/actions/workflows/rust.yml/badge.svg)

# Multihash

Multiformats multihash implementation without size in the type signature. Uses
Expand All @@ -7,3 +12,38 @@ encoding/decoding to/from strings and byte slices for multihashes. It also has
serde support to/from human readable and binary formats. It also supports raw
binary encoding and decoding using [`Into<Vec<u8>>`] and [`TryFrom<&[u8]>`]
trait implementations.

## Examples

Bulding a multihash from some bytes:

```rust
let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
.try_build()?;
```

Building a base encoded multihash from some bytes:

```rust
let encoded_mh = Builder::new_from_bytes(Codec::Sha3256, b"for great justice, move every zig!")?
.with_base_encoding(Base::Base58Btc)
.try_build_encoded()?;
```

Existing multihash objects can be converted to [`crate::mh::EncodedMultihash`]
objects by using `.into()`:

```rust
let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
.try_build()?;

// this will use the preferred encoding for multihash objects: Base::Base16Lower
let encoded_mh1: EncodedMultihash = mh.into();

// or you can chose the base enccoding...
let encoded_mh2: EncodedMultihash::new(Base::Base32Upper, mh);
```

[CRYPTID]: https://cryptid.tech/
[PROVENANCE]: https://github.com/cryptidtech/provenance-specifications/
[MULTIFORMATS]: https://github.com/multiformats/multiformats/
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
/// Errors created by this library
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
//!
#![warn(missing_docs)]
#![deny(
Expand Down
1 change: 1 addition & 0 deletions src/mh.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
use crate::Error;
use core::fmt;
use digest::{Digest, DynDigest};
Expand Down
1 change: 1 addition & 0 deletions src/serde/de.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
use crate::{mh::SIGIL, Multihash};
use core::fmt;
use multicodec::Codec;
Expand Down
1 change: 1 addition & 0 deletions src/serde/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
//! Serde (de)serialization for [`crate::Multihash`]
mod de;
mod ser;
Expand Down
1 change: 1 addition & 0 deletions src/serde/ser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Idnetifier: Apache-2.0
use crate::mh::{Multihash, SIGIL};
use multiutil::{EncodingInfo, Varbytes};
use serde::ser::{self, SerializeStruct};
Expand Down

0 comments on commit 325657d

Please sign in to comment.