Skip to main content

Crate vr_jcs

Crate vr_jcs 

Source
Expand description

§vr-jcs

RFC 8785 JSON Canonicalization Scheme (JCS) for Rust.

Produces canonical JSON suitable for deterministic digest computation, content hashing, and stable serialization boundaries. Implements the RFC 8785 rules that materially affect wire compatibility:

  • UTF-16 code-unit sorting for object property names
  • ECMAScript-compatible primitive serialization
  • UTF-8 output without insignificant whitespace
  • duplicate-property rejection on raw JSON parse paths
  • I-JSON string / number validation

§API

§Strict path (for untrusted JSON)

§Typed path (caller-controlled construction only, deprecated)

  • to_canon_bytes — Serialize any Serialize type to canonical JSON bytes
  • to_canon_string — Serialize any Serialize type to a canonical JSON string

§In-place

  • canonicalize — Sort object keys recursively in a serde_json::Value

§Usage

let json = vr_jcs::to_canon_string_from_str(r#"{"z_field":1,"a_field":2}"#)?;
assert_eq!(json, r#"{"a_field":2,"z_field":1}"#);

Enums§

JcsError
Error type for canonical JSON operations.

Constants§

MAX_NESTING_DEPTH
Maximum permitted nesting depth for JSON structures (128).

Functions§

canonicalize
Recursively sort all object keys in a JSON value for canonical representation.
to_canon_bytesDeprecated
Serialize any Serialize type to canonical JSON bytes.
to_canon_bytes_from_slice
Parse untrusted JSON, apply strict admission checks, and emit canonical RFC 8785 bytes.
to_canon_stringDeprecated
Serialize any Serialize type to a canonical JSON string.
to_canon_string_from_str
Parse untrusted JSON text, apply strict admission checks, and emit a canonical RFC 8785 string.