Indefinite length and deterministic encoding
CBOR allows several encodings of one value. The integer 1 is 0x01, but 0x18 0x01 is valid too; the array [1,2] is 0x82 0x01 0x02, but 0x9f 0x01 0x02 0xff is also valid CBOR.
Why that matters
Signatures and hashes cover the byte string itself. Encoding the same value differently changes the signature, so implementations need a rule that makes one value produce one byte string. That rule is deterministic encoding in RFC 8949 §4.2.
Core Deterministic Encoding
- Integers use the shortest header: 23 or less in one byte, 24 to 255 as
0x18plus one byte, and so on. - Strings, arrays and maps use a definite length; indefinite length is never used.
- Map keys are sorted bytewise by their deterministic encoding.
- Floats use the smallest width that keeps the value (Float16, then Float32, then Float64), and NaN is
0xf9 0x7e 0x00.
Ordering compares bytes from the left
There are two ways to order keys: shorter keys first, or by byte value. The core rule of RFC 8949 compares the encoded bytes lexicographically, so the integer key 1 (0x01) comes before the text key "a" (0x61 0x61).
What this tool checks
warn.nonShortest- a value written in a longer header than necessarywarn.indef- indefinite length was used (valid, but not deterministic)warn.keyOrder- map keys are not in bytewise orderwarn.dupKey- the same key appears twice
With deterministic encoding switched on, JSON to CBOR encoding applies these rules. With it off, the key order in the JSON and Float64 widths are kept as written.
Questions
When is indefinite length useful?
When streaming a value whose size is not known yet. If the bytes will be signed or hashed, re-encode them deterministically first.
Do implementations order keys differently?
Some older implementations sort by length first. RFC 8949 makes bytewise lexicographic order the core rule and discourages the other for interoperability.
Does narrowing to Float16 change the value?
Only when the value survives exactly. 1.5 and 65504 are exact in Float16, but 0.1 is not and stays a Float64.
The noncanonical preset shows a non-minimal header, broken key order, a duplicate key, 1.5 written as Float64 and a trailing byte together.
Written against RFC 8949 (CBOR), RFC 9052 (COSE), RFC 8392 (CWT) and the IANA COSE algorithm registry. Every byte string and key here is synthetic.