codec_cbor/lib.rs
1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! Deterministic DAG-CBOR codec for authoritative, cryptographically
6//! signed data.
7//!
8//! The decoder is strict by construction: it rejects non-canonical
9//! integers, indefinite-length items, floats, tags, out-of-order map keys,
10//! and trailing bytes, so a given value has exactly one accepted encoding.
11//! Decoding untrusted input is bounded in both memory and stack depth —
12//! container length prefixes are checked against the remaining input
13//! before any allocation, and nesting is capped at
14//! [`MAX_NESTING_DEPTH`] — so neither a crafted length nor pathological
15//! nesting can drive an out-of-memory or stack-overflow abort.
16
17mod cid;
18mod decode_dag_cbor;
19mod encode_dag_cbor;
20mod error;
21mod value;
22
23/// Maximum array/map nesting depth accepted by [`decode_dag_cbor`].
24///
25/// Authoritative documents in this system are shallow; this bound is far
26/// above any legitimate structure while still stopping a hostile input
27/// from recursing the decoder into a stack overflow.
28pub const MAX_NESTING_DEPTH: usize = 128;
29
30pub use cid::{
31 compute_cid_dag_cbor, dag_cbor_multihash, is_valid_cid_string, sha2_256_content_hash,
32 try_parse_cid, verify_dag_cbor_cid, ContentHash, DagCborMultihash, DAG_CBOR_CODEC,
33};
34pub use decode_dag_cbor::decode_dag_cbor;
35pub use encode_dag_cbor::encode_dag_cbor;
36pub use error::CborError;
37pub use value::CborValue;