pub struct Canonicalizer { /* private fields */ }Expand description
Provides deterministic canonicalization and hashing of content Implements explicit v1 algorithms for YAML and Markdown canonicalization
Implementations§
Source§impl Canonicalizer
impl Canonicalizer
Sourcepub fn new() -> Canonicalizer
pub fn new() -> Canonicalizer
Create a new canonicalizer with the current version
Sourcepub fn canonicalize_yaml(&self, content: &str) -> Result<String, Error>
pub fn canonicalize_yaml(&self, content: &str) -> Result<String, Error>
Canonicalize YAML content (v1 algorithm) Uses JCS (JSON Canonicalization Scheme) approach:
-
Parse YAML → convert to JSON with deterministic maps (
BTreeMap) -
Keep human-readable YAML on disk (normalized: LF, trim trailing spaces, final newline)
-
For hashing: use JCS canonicalization of the JSON representation
Reserved for future content-addressed verification
Sourcepub fn normalize_markdown(&self, content: &str) -> Result<String, Error>
pub fn normalize_markdown(&self, content: &str) -> Result<String, Error>
Normalize Markdown content (v1 algorithm) Explicit rules:
- Normalize \n, trim trailing spaces, collapse trailing blank lines to 1
- Fence normalization: ``` with language tag preserved
- Final newline enforced
- Normalize heading underlines to # style
- Stable ordering where structure allows
Sourcepub fn normalize_text(&self, content: &str) -> String
pub fn normalize_text(&self, content: &str) -> String
Normalize plain text content
Sourcepub fn hash_canonicalized(
&self,
content: &str,
file_type: FileType,
) -> Result<String, Error>
pub fn hash_canonicalized( &self, content: &str, file_type: FileType, ) -> Result<String, Error>
Compute BLAKE3 hash of canonicalized content with FileType dispatch
For YAML: uses JCS (RFC 8785) canonicalization of JSON representation
For Markdown: uses v1 normalization rules
For Text: uses basic line ending normalization
Sourcepub fn hash_canonicalized_with_context(
&self,
content: &str,
file_type: FileType,
phase: &str,
) -> Result<String, XCheckerError>
pub fn hash_canonicalized_with_context( &self, content: &str, file_type: FileType, phase: &str, ) -> Result<String, XCheckerError>
Compute BLAKE3 hash of canonicalized content with error context