cipherstash-config 0.40.0

Configuration management for CipherStash libraries and products
Documentation
use serde::{Deserialize, Serialize};

/// Selects the per-entry orderable-term primitive used by a `ste_vec` index.
///
/// Selectors are always Blake3-keyed and term-side MACs are always
/// HMAC-SHA256 in both modes; only the ordering term differs. Indexes
/// produced under different modes are not cross-comparable, so the indexing
/// side and the query side must agree on the mode for results to match.
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum SteVecMode {
    /// CLLW OPE — order-preserving ciphertexts carried on the sv-level `op`
    /// key. Ciphertext bytes compare in plain byte order, so the database
    /// needs no ORE-aware comparator. This is the EQL v3 / Supabase-compatible
    /// mode, and the default.
    #[default]
    Compat,
    /// CLLW ORE — ciphertexts carried on the sv-level `oc` key, compared with
    /// an ORE-aware comparator. The legacy v2 protocol, still used by Proxy /
    /// v2 consumers.
    Standard,
}

#[cfg(test)]
mod tests {
    use super::SteVecMode;
    use serde_json::json;

    #[test]
    fn test_default_is_compat() {
        assert_eq!(SteVecMode::default(), SteVecMode::Compat);
    }

    #[test]
    fn test_serializes_kebab_case() {
        assert_eq!(
            serde_json::to_value(SteVecMode::Compat).unwrap(),
            json!("compat")
        );
        assert_eq!(
            serde_json::to_value(SteVecMode::Standard).unwrap(),
            json!("standard")
        );
    }

    #[test]
    fn test_deserializes_kebab_case() {
        let compat: SteVecMode = serde_json::from_value(json!("compat")).unwrap();
        let standard: SteVecMode = serde_json::from_value(json!("standard")).unwrap();
        assert_eq!(compat, SteVecMode::Compat);
        assert_eq!(standard, SteVecMode::Standard);
    }
}