Skip to main content

ngdp_crypto/
error.rs

1//! Error types for ngdp-crypto operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during crypto operations.
6#[derive(Error, Debug)]
7pub enum CryptoError {
8    /// Key not found in key service.
9    #[error("encryption key not found: {0:016x}")]
10    KeyNotFound(u64),
11
12    /// Invalid key format.
13    #[error("invalid key format: {0}")]
14    InvalidKeyFormat(String),
15
16    /// Invalid key size.
17    #[error("invalid key size: expected {expected}, got {actual}")]
18    InvalidKeySize { expected: usize, actual: usize },
19
20    /// Invalid IV size.
21    #[error("invalid IV size: expected {expected}, got {actual}")]
22    InvalidIvSize { expected: usize, actual: usize },
23
24    /// IO error.
25    #[error("IO error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Invalid key file format.
29    #[error("invalid key file format: {0}")]
30    InvalidKeyFile(String),
31
32    /// Decryption failed.
33    #[error("decryption failed: {0}")]
34    DecryptionFailed(String),
35
36    /// Invalid block index.
37    #[error("invalid block index: {0}")]
38    InvalidBlockIndex(usize),
39
40    /// Invalid parameter.
41    #[error("invalid parameter: {0}")]
42    InvalidParameter(String),
43
44    /// Initialization failed.
45    #[error("initialization failed: {0}")]
46    InitializationFailed(String),
47}