cipherstash-client 0.34.1-alpha.4

The official CipherStash SDK
Documentation
//! Cross-cutting helpers for fitting a value's
//! [`orderable_bytes::ToOrderableBytes`] encoding into a fixed 8-byte
//! plaintext block. The 8-byte width is consumed by 8-byte block
//! ORE/OPE schemes regardless of the underlying cipher.

/// Zero-extend orderable bytes (≤ 8 bytes) into a fixed `[u8; 8]` block
/// by left-padding with zeros — short encodings sit in the low bytes of
/// the resulting block, matching the legacy `value as uN as u64`
/// widening. Lex order of the orderable bytes survives the widening, so
/// the resulting block's lex order matches the underlying value's
/// natural order.
pub(crate) fn pad_orderable_to_8(bytes: &[u8]) -> [u8; 8] {
    debug_assert!(bytes.len() <= 8, "orderable bytes must fit in 8 bytes");
    let mut padded = [0u8; 8];
    padded[8 - bytes.len()..].copy_from_slice(bytes);
    padded
}

/// Same widening as [`pad_orderable_to_8`] but reinterprets the
/// resulting block as a big-endian `u64`. Used by call sites that need
/// a numeric `u64` plaintext (e.g. `OreTerm::Number`).
pub(crate) fn orderable_to_u64(bytes: &[u8]) -> u64 {
    u64::from_be_bytes(pad_orderable_to_8(bytes))
}