1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// SPDX-License-Identifier: Apache-2.0
//! # multi-cid
//!
//! Content Identifier (CID) implementation compatible with IPFS and IPLD.
//!
//! ## Overview
//!
//! This crate provides CID (Content Identifier) support for self-describing content
//! addresses. CIDs are used extensively in IPFS and IPLD to create cryptographically
//! secure, content-addressed links.
//!
//! This crate contains only the `Cid` half of the former `bs-multicid` crate. The
//! `Vlad` half lives in the standalone `multi-vlad` crate. The split lets a
//! downstream crate depend on only the type it needs: `multi-cid` does not pull in
//! `multi-key` or `multi-sig`, which were only required by `Vlad`.
//!
//! ## CID Versions
//!
//! - **CID v0**: Legacy format, base58btc encoded, implicit dag-pb codec
//! - **CID v1**: Modern format, supports multibase, explicit codec and version
//!
//! ## Quick Start
//!
//! ### Creating a CID
//!
//! ```rust
//! use multi_cid::cid;
//! use multi_codec::Codec;
//! use multi_hash::Builder as MhBuilder;
//!
//! // Create a multihash
//! let hash = MhBuilder::new_from_bytes(Codec::Sha2256, b"hello world")
//! .unwrap()
//! .try_build()
//! .unwrap();
//!
//! // Create a CID v1
//! let cid = cid::Builder::new(Codec::Sha2256)
//! .with_target_codec(Codec::DagCbor)
//! .with_hash(&hash)
//! .try_build()
//! .unwrap();
//! ```
//!
//! ### Encoding and Decoding
//!
//! ```rust
//! use multi_cid::cid;
//! use multi_codec::Codec;
//! use multi_hash::Builder as MhBuilder;
//!
//! let hash = MhBuilder::new_from_bytes(Codec::Sha2256, b"data")
//! .unwrap()
//! .try_build()
//! .unwrap();
//!
//! let cid = cid::Builder::new(Codec::Sha2256)
//! .with_target_codec(Codec::DagCbor)
//! .with_hash(&hash)
//! .try_build()
//! .unwrap();
//!
//! // CID created successfully
//! let bytes: Vec<u8> = cid.into();
//! assert!(!bytes.is_empty());
//! ```
//!
//! ## Features
//!
//! - **`serde`** (default): Enables serde serialization
//! - **`dag_cbor`**: Enables CBOR tag 42 support for DAG-CBOR links via `multi-cbor`
//!
//! ## DAG-CBOR Support
//!
//! When the `dag_cbor` feature is enabled, CIDs can be serialized with CBOR tag 42
//! for use in IPLD DAG-CBOR documents.
// Pedantic/nursery/cargo lints are enabled in `[lints.clippy]` in Cargo.toml.
/// Errors produced by this library
pub use ;
/// Cid content identifier types
pub use ;
/// Type-safe wrappers for CID components
pub use ;
/// Serde serialization for Cid
/// Commonly used items
///
/// ```
/// use multi_cid::prelude::*;
/// use multi_hash::Builder as MhBuilder;
///
/// let hash = MhBuilder::new_from_bytes(Codec::Sha2256, b"test")
/// .unwrap()
/// .try_build()
/// .unwrap();
/// let cid = cid::Builder::new(Codec::Sha2256)
/// .with_target_codec(Codec::DagCbor)
/// .with_hash(&hash)
/// .try_build()
/// .unwrap();
/// ```