Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonical CBOR encoding.

Every BoundGraph primitive is content-addressed by the digest of its canonical encoding, so the encoding must be a function of the value: the same logical value must always produce byte-identical output, on any platform, in any process.

serde alone does not give that. It emits struct fields in declaration order and emits map entries in iteration order, so two equal values can encode differently. We therefore serialise to a ciborium::Value tree, rewrite it into deterministic form, and only then emit bytes.

Deterministic form follows RFC 8949 §4.2.1: map keys are sorted bytewise and lexicographically by their own encoded representation, not by their logical value. Sorting by logical value would order 1 before "a" in one encoder and after it in another; sorting by encoded bytes is unambiguous.

Enums§

CanonicalError
Something went wrong turning a value into (or back out of) canonical bytes.

Traits§

Canonical
Blanket helper: the content address of any serialisable value.

Functions§

from_canonical_cbor
Decode canonical CBOR produced by to_canonical_cbor.
to_canonical_cbor
Encode value as canonical CBOR.