Is https://docs.rs/cbor/latest/cbor/ deterministic?

It’s a well known fact that CBOR is not a deterministic format, that is the same object may be encoded in several ways.

Is however the library implementation cbor - Rust deterministic? Is it future-compatible to itself?

If not, which library can you propose to convert an object to the binary format in a deterministic way?

1 Like

Deterministic Encoding Options

  • dcbor: This Rust crate is purpose-built for Deterministic CBOR (dCBOR). It strictly enforces the rules (like sorted map keys and minimal integer forms) to ensure a single, consistent binary output every time. If you need true dCBOR, this is your best bet.
  • FlatBuffers: A different approach entirely. FlatBuffers uses a schema to define your data, and then it’s serialized directly into memory. This makes it inherently highly deterministic, always producing the same byte sequence for the same data. It excels where strict byte-for-byte reproducibility is critical, but it requires using .fbs schema files and a separate compiler.

I gathered this information from an AI model, and I don’t have hands-on experience with either dcbor or flatbuffers in Rust. I strongly recommend you dive into their documentation and test them thoroughly to confirm they meet your exact determinism needs.

2 Likes