mod canonicalize#
- module canonicalize#
RFC 8785 JSON Canonicalization and whitespace normalization for cache stability.
This module provides deterministic JSON serialization (RFC 8785 / JCS) and whitespace normalization so that semantically equivalent content always produces byte-identical output. This is critical for cache key stability: without canonicalization, tool schemas or JSON content with different key orders would produce different hashes and miss the cache.
Public functions
canonicalize_json– Canonicalize a JSON string per RFC 8785.canonicalize_value– Canonicalize aserde_json::Valueper RFC 8785.normalize_whitespace– Trim and collapse whitespace in text content.sha256_hex– Compute SHA-256 hex digest with"sha256:"prefix.
Functions
- fn canonicalize_json(json_str: &str) -> Result<String>#
Canonicalize a JSON string per RFC 8785 (JCS).
Parses the input as JSON, then re-serializes using deterministic key ordering and number formatting per the JSON Canonicalization Scheme.
Errors
Returns
AcgError::Serializationif the input is not valid JSON or if canonicalization fails.
- fn canonicalize_value(value: &serde_json::Value) -> Result<String>#
Canonicalize a
serde_json::Valueper RFC 8785.Errors
Returns
AcgError::Serializationif canonicalization fails.
- fn normalize_whitespace(text: &str) -> String#
Normalize whitespace in text content.
Trims leading and trailing whitespace.
Collapses runs of horizontal whitespace (spaces, tabs, and other Unicode whitespace characters except
\n) into a single ASCII space.Preserves single newline characters (they separate paragraphs in prompts).
- fn sha256_hex(input: &str) -> String#
Compute SHA-256 hex digest with
"sha256:"prefix.The output format is
sha256:<hex>where<hex>is the lowercase hexadecimal encoding of the 256-bit digest.