cognee-telemetry 0.1.3

Opt-in product-analytics telemetry for the cognee AI-memory pipeline.
Documentation
#![allow(
    clippy::unwrap_used,
    clippy::expect_used,
    reason = "test code — panics are acceptable failures"
)]
//! Byte-level parity test for PBKDF2-HMAC-SHA256.
//!
//! The fixture is generated by
//! `scripts/generate_python_fixtures.py` against Python's stdlib
//! `hashlib.pbkdf2_hmac`. If this test fails, either:
//! - the Rust implementation has drifted from PBKDF2 spec, or
//! - the fixture is stale (regenerate with the script).
//!
//! Either way, the parity contract is broken — investigate before
//! merging.

#![cfg(feature = "telemetry")]

use hmac::Hmac;
use pbkdf2::pbkdf2;
use serde::Deserialize;
use sha2::Sha256;

#[derive(Debug, Deserialize)]
struct Vector {
    key: String,
    salt: String,
    iter: u32,
    dklen: usize,
    expected_hex: String,
}

#[test]
fn pbkdf2_byte_parity_with_python() {
    let raw = std::fs::read_to_string("tests/fixtures/pbkdf2_vectors.json")
        .expect("fixture present at tests/fixtures/pbkdf2_vectors.json");
    let vectors: Vec<Vector> = serde_json::from_str(&raw).expect("fixture parses");
    assert!(
        !vectors.is_empty(),
        "fixture must contain at least one vector"
    );

    for (i, v) in vectors.iter().enumerate() {
        assert_eq!(
            v.dklen, 16,
            "vector {i}: only dklen=16 is supported; regenerate fixture if it changed"
        );
        let mut out = vec![0u8; v.dklen];
        pbkdf2::<Hmac<Sha256>>(v.key.as_bytes(), v.salt.as_bytes(), v.iter, &mut out)
            .expect("pbkdf2 cannot fail for dklen <= 32");
        assert_eq!(
            hex::encode(&out),
            v.expected_hex,
            "byte parity drift on vector {i} (key={:?}, salt={:?})",
            v.key,
            v.salt,
        );
    }
}