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],Decimaland thechronotypes.VariableOrderableBytes: the length varies with the value, and the bytes are borrowed from it. Strings and byte strings (seevariable).
A reference &T implements the same traits as T.
| Need | Bound | Call |
|---|---|---|
| Pad, store or return fixed-length bytes | T: FixedOrderableBytes | to_fixed_orderable_bytes (owned) |
| Bytes of either kind, used immediately | T: OrderableBytes | to_orderable_bytes (may borrow) |
| Strings or byte strings specifically | T: VariableOrderableBytes | to_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 floatsf32andf64, and byte arrays[u8; N]. - variable
- Canonical, order-preserving variable-length byte encodings for
str,String,[u8]andVec<u8>.
Traits§
- Fixed
Orderable Bytes - An
OrderableBytesencoding whose length is the same for every value of the type. - Orderable
Bytes - Maps a value to its canonical, order-preserving byte encoding.
- Variable
Orderable Bytes - An
OrderableBytesencoding whose length varies with the value.