dcrypt_kem/error/
validate.rs

1//! Validation utilities for KEM operations
2
3use super::{Error, Result};
4
5/// Validate key pair generation parameters
6pub fn key_generation(
7    condition: bool,
8    algorithm: &'static str,
9    details: &'static str,
10) -> Result<()> {
11    if !condition {
12        return Err(Error::KeyGeneration { algorithm, details });
13    }
14    Ok(())
15}
16
17/// Validate encapsulation parameters
18pub fn encapsulation(
19    condition: bool,
20    algorithm: &'static str,
21    details: &'static str,
22) -> Result<()> {
23    if !condition {
24        return Err(Error::Encapsulation { algorithm, details });
25    }
26    Ok(())
27}
28
29/// Validate decapsulation parameters
30pub fn decapsulation(
31    condition: bool,
32    algorithm: &'static str,
33    details: &'static str,
34) -> Result<()> {
35    if !condition {
36        return Err(Error::Decapsulation { algorithm, details });
37    }
38    Ok(())
39}
40
41/// Validate key format
42pub fn key(condition: bool, key_type: &'static str, reason: &'static str) -> Result<()> {
43    if !condition {
44        return Err(Error::InvalidKey { key_type, reason });
45    }
46    Ok(())
47}
48
49/// Validate ciphertext format
50pub fn ciphertext(condition: bool, algorithm: &'static str, reason: &'static str) -> Result<()> {
51    if !condition {
52        return Err(Error::InvalidCiphertext { algorithm, reason });
53    }
54    Ok(())
55}
56
57/// Validate serialization format
58pub fn serialization(condition: bool, context: &'static str, details: &'static str) -> Result<()> {
59    if !condition {
60        return Err(Error::Serialization { context, details });
61    }
62    Ok(())
63}
64
65// Re-export primitive validations for convenience
66pub use dcrypt_api::error::validate::{length, max_length, min_length, parameter};