canaad-core
Parse, validate, and canonicalize AAD contexts per RFC 8785.
use it
Parse existing JSON:
use parse;
let json = r#"{"v":1,"tenant":"org_abc","resource":"secrets/db","purpose":"encryption"}"#;
let ctx = parse?;
let canonical = ctx.canonicalize_string?;
Build from scratch:
use AadContext;
let ctx = new?
.with_timestamp?
.with_string_extension?;
let bytes = ctx.canonicalize?;
Use the builder if you prefer:
use AadContext;
let ctx = builder
.tenant
.resource
.purpose
.extension_string
.build?;
Builder defers all validation to build() — invalid extensions surface as errors, not silent drops.
what it checks
vmust be 1tenant: 1-256 bytes, no NULresource: 1-1024 bytes, no NULpurpose: 1+ bytes, no NULts: optional, 0 to 2^53-1- extensions:
x_<app>_<field>pattern, values are strings or integers - no duplicate keys (custom scanner, not serde_json)
- 16 KiB max serialized size
All 16 error variants are strongly typed via AadError. Run cargo doc -p canaad-core --open for the full API.
spec
See aad-spec.md for the complete specification and test vectors.