Expand description
§sacp-cbor
Strict deterministic CBOR validation and canonical encoding for the SACP-CBOR/1 profile used by the Synext Agent Control Protocol (SACP).
§Design principles
- Canonical bytes are the value. Under SACP-CBOR/1, any valid encoding is canonical; therefore, semantic equality for opaque payloads reduces to byte equality.
- Hot-path validation is allocation-free.
Use
validate_canonicalto validate a single CBOR data item with strict SACP-CBOR/1 rules. - Encoding is streaming-first.
Use
Encoderorcbor_bytes!to emit canonical bytes without building an owned tree.
§SACP-CBOR/1 profile (explicit)
Terminology note: “canonical” in this crate means canonical under the strict SACP-CBOR/1 profile defined here, not RFC 8949 canonical CBOR.
Allowed data model
- Single CBOR item only (no trailing bytes).
- Definite-length items only (no indefinite-length encodings).
- Map keys must be text strings (major 3) and valid UTF-8.
- Only tags 2 and 3 are allowed (bignums), and bignums must be canonical and outside the safe-int range.
- Integers (major 0/1) must be in the safe range
[-(2^53-1), +(2^53-1)]. - Floats must be encoded as float64 (major 7, ai=27), forbid
-0.0, and require the canonical NaN bit pattern. - Only simple values
false,true, andnullare allowed.
Canonical encoding constraints
- Minimal integer/length encoding (no overlong forms).
- Map keys are strictly increasing by canonical CBOR key ordering:
(encoded length, then lexicographic encoded bytes).
§Feature flags
std(default): implementsstd::error::ErrorforCborError.alloc(default): enables owned canonical bytes (CanonicalCbor), editing, and encoding helpers.sha2(default): enables SHA-256 hashing helpers for canonical bytes.simdutf8: enables SIMD-accelerated UTF-8 validation where supported.unsafe: allows unchecked UTF-8 for canonical-trusted inputs.
§Safety
This crate forbids unsafe code by default. Enabling the unsafe feature allows
unchecked UTF-8 conversion on canonical-trusted inputs.
§no_std
The crate is no_std compatible.
- Validation-only usage works without
alloc. - Owned APIs (canonical bytes + editor) require
allocand therefore an allocator provided by your environment.
Macros§
- cbor_
bytes alloc - Construct canonical CBOR bytes with a JSON-like literal syntax.
- path
- Construct a path slice for query/edit operations.
Structs§
- Array
Decoder - Array decoder guard that manages depth and length.
- Array
Encoder alloc - Builder for writing array elements into a canonical CBOR stream.
- Array
Ref - A borrowed view into a canonical CBOR array.
- Array
Splice Builder alloc - Builder for an array splice edit.
- BigInt
alloc - A tagged bignum integer (CBOR tag 2 or 3).
- BigInt
Ref - A borrowed view of a CBOR bignum (tag 2 / tag 3).
- Canonical
Cbor alloc - An owned canonical SACP-CBOR/1 data item.
- Canonical
Cbor Ref - A validated canonical SACP-CBOR/1 data item borrowed from an input buffer.
- Cbor
Error - An SACP-CBOR/1 error with structured classification, a stable code, and a byte offset.
- Cbor
Integer alloc - An integer value permitted by SACP-CBOR/1.
- Cbor
Limits - End-to-end limits used by SACP implementations.
- Cbor
Value Ref - A borrowed view into a canonical CBOR message.
- DeError
serde - A serde decoding error that preserves an
ErrorCodeplus an input offset. - Decode
Limits - Decode-time resource limits for validation and decoding.
- Decoder
- Streaming decoder over canonical CBOR bytes.
- Edit
Options alloc - Edit behavior options.
- Edit
Value alloc - Encoded edit value used by the editor.
- Editor
alloc - Incremental editor for canonical CBOR bytes.
- Encoded
Text Key - A validated canonical CBOR-encoded text-string key.
- Encoder
alloc - Streaming encoder that writes canonical CBOR directly into a
Vec<u8>. - F64Bits
- A validated float64 bit-pattern suitable for SACP-CBOR/1 encoding.
- MapDecoder
- Map decoder guard that manages depth, length, and key ordering.
- MapEncoder
alloc - Builder for writing map entries into a canonical CBOR stream.
- MapEntries
alloc - A CBOR map represented as ordered key/value entries.
- MapRef
- A borrowed view into a canonical CBOR map.
Enums§
- Array
Pos alloc - Array splice position.
- Cbor
Integer Ref - A borrowed view of an integer (safe or bignum).
- Cbor
Kind - The CBOR data model supported by this crate.
- Delete
Mode alloc - Mode for delete operations.
- Error
Code - A structured error code identifying the reason a CBOR item was rejected.
- Path
Elem - A path element for navigating inside a CBOR value.
- SetMode
alloc - Mode for map set operations.
Constants§
- MAX_
SAFE_ INTEGER - Maximum safe integer (2^53-1).
- MAX_
SAFE_ INTEGER_ I64 - Maximum safe integer as i64 (2^53-1).
- MIN_
SAFE_ INTEGER - Minimum safe integer (-(2^53-1)).
Traits§
- Cbor
Array Elem alloc - Marker trait for values that can appear as CBOR array elements.
- Cbor
Decode - Decode a value from a streaming decoder.
- Cbor
Encode alloc - Encode a value into canonical CBOR bytes using the streaming encoder.
- Edit
Encode alloc - Encodes a single canonical CBOR value into an
Encoder.
Functions§
- decode
- Validate canonical CBOR and decode a value using
CborDecode. - decode_
canonical - Decode a value from validated canonical bytes.
- decode_
canonical_ owned alloc - Decode a value from owned canonical bytes.
- encode_
into alloc - Encode a value into an existing encoder, reusing its capacity.
- encode_
to_ canonical alloc - Encode a value into owned canonical CBOR bytes.
- encode_
to_ vec alloc - Encode a value into canonical CBOR bytes.
- from_
canonical_ bytes serde - Deserialize
Tfrom owned canonical bytes without re-checking canonical encodings. - from_
canonical_ bytes_ ref serde - Deserialize
Tfrom validated canonical bytes without re-checking canonical encodings. - from_
slice serde - Deserialize a Rust value from canonical SACP-CBOR/1 bytes.
- from_
slice_ borrowed serde - Deserialize
Twith zero-copy borrows, validating during parsing. - to_vec
serde - Serialize a Rust value into canonical SACP-CBOR/1 bytes.
- to_
vec_ sorted_ maps serde - Serialize a Rust value into canonical SACP-CBOR/1 bytes while sorting map keys.
- validate
- Validate that
bytescontain exactly one canonical SACP-CBOR/1 data item. - validate_
canonical - Validate that
bytescontain exactly one canonical SACP-CBOR/1 data item and return a wrapper.
Type Aliases§
- Checked
Decoder - Decoder that enforces canonical constraints while decoding.
- Trusted
Decoder - Decoder that trusts inputs are already canonical.
Derive Macros§
- Cbor
Decode - Derive canonical CBOR decoding for structs and enums.
- Cbor
Encode - Derive canonical CBOR encoding for structs and enums.