Skip to main content

codec_cbor/
lib.rs

1// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! Borrowed general CBOR, deterministic CBOR, and a DAG-CBOR subset with CID helpers.
6//!
7//! The existing deterministic and DAG profiles use length-first key ordering
8//! (RFC 8949 ยง4.2.3) and reject 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//! DAG-CBOR supports text map keys and signed 64-bit integers. Generic CBOR
12//! also supports integer map keys and the full unsigned 64-bit range.
13//! Input-size and nesting limits bound parser work; declared container lengths
14//! are checked against remaining input before allocating their contents.
15//!
16//! [`general`] is a separate borrowed surface for arbitrary tags, received spans,
17//! unsorted unique maps, complete integer arguments, and IEEE floats. Its framing,
18//! basic-validity, and preferred-encoding operations have distinct guarantees.
19
20mod check_map_key_order;
21mod cid;
22mod decode_dag_cbor;
23mod decode_deterministic_cbor;
24mod deterministic;
25mod encode_dag_cbor;
26mod encode_deterministic_cbor;
27mod error;
28mod value;
29
30#[cfg(kani)]
31mod nested_map_proof_tests;
32
33/// Borrowed general CBOR with independently selected framing and validity policies.
34pub mod general;
35
36mod limits;
37pub use limits::{
38    MAX_DAG_CBOR_CONTAINER_ENTRIES, MAX_DAG_CBOR_INPUT_LEN, MAX_DAG_CBOR_NODES, MAX_NESTING_DEPTH,
39};
40
41pub use cid::{
42    compute_cid_dag_cbor, dag_cbor_multihash, is_valid_cid_string, sha2_256_content_hash,
43    try_parse_cid, verify_dag_cbor_cid, CidVerificationStatus, ContentHash, DagCborCidVerification,
44    DagCborMultihash, ParsedCid, DAG_CBOR_CODEC, MAX_CID_STRING_LEN,
45};
46pub use decode_dag_cbor::decode_dag_cbor;
47pub use decode_deterministic_cbor::decode_deterministic_cbor;
48pub use deterministic::{
49    DeterministicCborError, DeterministicCborInteger, DeterministicCborMapEntry,
50    DeterministicCborMapKey, DeterministicCborNegativeInteger, DeterministicCborProfileError,
51    DeterministicCborValue, DETERMINISTIC_CBOR_NEGATIVE_MAX, DETERMINISTIC_CBOR_NEGATIVE_MIN,
52    MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES,
53    MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES, MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES,
54    MAX_DETERMINISTIC_CBOR_INPUT_LEN, MAX_DETERMINISTIC_CBOR_NESTING_DEPTH,
55    MAX_DETERMINISTIC_CBOR_NODES, MAX_DETERMINISTIC_CBOR_OUTPUT_LEN,
56};
57pub use encode_dag_cbor::encode_dag_cbor;
58pub use encode_deterministic_cbor::encode_deterministic_cbor;
59pub use error::CborError;
60pub use value::CborValue;