Skip to main content

Crate orderable_bytes

Crate orderable_bytes 

Source
Expand description

Canonical, order-preserving byte encodings for plaintext types.

Each supported type implements OrderableBytes, which maps a value to bytes whose byte-wise lexicographic order agrees with the type’s natural total order, and whose byte equality agrees with the type’s value equality. The resulting bytes are scheme-agnostic — they’re intended for any comparison-as-bytes scheme that wants to preserve plaintext order on ciphertexts (e.g. ore-rs BlockORE, an OPE construction, an ordered hash).

Every type also implements exactly one of two subtraits, which say how its bytes may be handled:

  • FixedOrderableBytes: every value encodes to the same length, ENCODED_LEN, available as an owned array. Numbers, bool, char, byte arrays [u8; N], Decimal and the chrono types.
  • VariableOrderableBytes: the length varies with the value, and the bytes are borrowed from it. Strings and byte strings (see variable).

A reference &T implements the same traits as T.

NeedBoundCall
Pad, store or return fixed-length bytesT: FixedOrderableBytesto_fixed_orderable_bytes (owned)
Bytes of either kind, used immediatelyT: OrderableBytesto_orderable_bytes (may borrow)
Strings or byte strings specificallyT: VariableOrderableBytesto_orderable_bytes (borrowed)

Padding to a block size is only safe for FixedOrderableBytes; bound on OrderableBytes only when you handle both kinds correctly.

The traits are sealed: only this crate implements them, so every encoding is pinned by its golden vectors, and the rules above hold for every type that implements them.

Encoders are gated behind per-type feature flags so callers only pay for the dependencies they actually use.

Modules§

primitive
Canonical, order-preserving fixed-length byte encodings for the primitives bool, char, u8, i8, i16, i32, i64, u128, i128, the IEEE 754 floats f32 and f64, and byte arrays [u8; N].
variable
Canonical, order-preserving variable-length byte encodings for str, String, [u8] and Vec<u8>.

Traits§

FixedOrderableBytes
An OrderableBytes encoding whose length is the same for every value of the type.
OrderableBytes
Maps a value to its canonical, order-preserving byte encoding.
VariableOrderableBytes
An OrderableBytes encoding whose length varies with the value.