Skip to main content

codec_jcs/
lib.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! RFC 8785 JSON Canonicalization Scheme.
6//!
7//! Produces the unique canonical byte string for a JSON value so that a
8//! signature computed over the output verifies across independent
9//! implementations. Correctness of two subtle areas — object member
10//! ordering by UTF-16 code unit and ECMAScript-conformant number
11//! serialization — is what makes that cross-stack guarantee hold; both are
12//! implemented to the RFC and covered by conformance tests.
13
14mod canonicalize;
15mod error;
16
17pub use canonicalize::canonicalize_json;
18pub use error::JcsError;
19
20/// Maximum array/object nesting depth accepted by [`canonicalize_json`].
21///
22/// Defense in depth: `serde_json`'s parser already caps nesting, but a
23/// caller may hand in a `Value` built by other means, so canonicalization
24/// enforces its own bound rather than trusting the input's provenance.
25pub const MAX_NESTING_DEPTH: usize = 128;