pub mod core;
pub mod key_derivation;
pub mod key_rotation;
pub use core::{EncryptionError, ZeroKnowledgeEncryptor};
pub use key_derivation::{derive_domain_key, KeyDerivationError};
pub use key_rotation::{KeyRotationState, RotationAwareHeader};
pub type EncryptionHeader = RotationAwareHeader;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyDomain {
Encryption,
Authentication,
CacheKeys,
}
impl KeyDomain {
pub fn as_str(&self) -> &'static str {
match self {
KeyDomain::Encryption => "encryption",
KeyDomain::Authentication => "authentication",
KeyDomain::CacheKeys => "cache_keys",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_encryption_header_roundtrip() {
let header = RotationAwareHeader::new([0x12; 16], [0x34; 8], *b"ench", 0);
let bytes = header.to_bytes();
let decoded = RotationAwareHeader::from_bytes(&bytes).unwrap();
assert_eq!(decoded.version, 1);
assert_eq!(decoded.key_fingerprint, [0x12; 16]);
assert_eq!(decoded.domain, *b"ench");
assert_eq!(decoded.key_version, 0); assert_eq!(bytes[1], 0);
}
#[test]
fn test_unsupported_algorithm_rejected() {
let mut bytes = [0u8; RotationAwareHeader::SIZE];
bytes[0] = 1; bytes[1] = 99;
let result = RotationAwareHeader::from_bytes(&bytes);
assert!(result.is_err());
}
#[test]
fn test_domain_strings() {
assert_eq!(KeyDomain::Encryption.as_str(), "encryption");
assert_eq!(KeyDomain::Authentication.as_str(), "authentication");
assert_eq!(KeyDomain::CacheKeys.as_str(), "cache_keys");
}
}