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 cid;
21mod decode_dag_cbor;
22mod decode_deterministic_cbor;
23mod deterministic;
24mod encode_dag_cbor;
25mod encode_deterministic_cbor;
26mod error;
27mod value;
28
29/// Borrowed general CBOR with independently selected framing and validity policies.
30pub mod general;
31
32mod limits;
33pub use limits::{
34    MAX_DAG_CBOR_CONTAINER_ENTRIES, MAX_DAG_CBOR_INPUT_LEN, MAX_DAG_CBOR_NODES, MAX_NESTING_DEPTH,
35};
36
37pub use cid::{
38    compute_cid_dag_cbor, dag_cbor_multihash, is_valid_cid_string, sha2_256_content_hash,
39    try_parse_cid, verify_dag_cbor_cid, CidVerificationStatus, ContentHash, DagCborCidVerification,
40    DagCborMultihash, ParsedCid, DAG_CBOR_CODEC, MAX_CID_STRING_LEN,
41};
42pub use decode_dag_cbor::decode_dag_cbor;
43pub use decode_deterministic_cbor::decode_deterministic_cbor;
44pub use deterministic::{
45    DeterministicCborError, DeterministicCborInteger, DeterministicCborMapEntry,
46    DeterministicCborMapKey, DeterministicCborNegativeInteger, DeterministicCborProfileError,
47    DeterministicCborValue, DETERMINISTIC_CBOR_NEGATIVE_MAX, DETERMINISTIC_CBOR_NEGATIVE_MIN,
48    MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES,
49    MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES, MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES,
50    MAX_DETERMINISTIC_CBOR_INPUT_LEN, MAX_DETERMINISTIC_CBOR_NESTING_DEPTH,
51    MAX_DETERMINISTIC_CBOR_NODES, MAX_DETERMINISTIC_CBOR_OUTPUT_LEN,
52};
53pub use encode_dag_cbor::encode_dag_cbor;
54pub use encode_deterministic_cbor::encode_deterministic_cbor;
55pub use error::CborError;
56pub use value::CborValue;