Skip to main content

tenzro_tee/
error.rs

1//! Error types for the Tenzro Network TEE module.
2
3use thiserror::Error;
4
5/// Result type for TEE operations.
6pub type Result<T> = std::result::Result<T, TeeError>;
7
8/// Errors that can occur in TEE operations.
9#[derive(Debug, Error)]
10pub enum TeeError {
11    /// TEE hardware is not available
12    #[error("TEE hardware not available: {0}")]
13    NotAvailable(String),
14
15    /// Attestation generation failed
16    #[error("Failed to generate attestation: {0}")]
17    AttestationGenerationFailed(String),
18
19    /// Attestation verification failed
20    #[error("Attestation verification failed: {0}")]
21    AttestationVerificationFailed(String),
22
23    /// Invalid attestation report
24    #[error("Invalid attestation report: {0}")]
25    InvalidAttestationReport(String),
26
27    /// Certificate chain validation failed
28    #[error("Certificate chain validation failed: {0}")]
29    CertificateValidationFailed(String),
30
31    /// TCB (Trusted Computing Base) version is outdated
32    #[error("TCB version outdated: current={current}, required={required}")]
33    TcbOutdated {
34        current: String,
35        required: String,
36    },
37
38    /// Enclave operation failed
39    #[error("Enclave operation failed: {0}")]
40    EnclaveOperationFailed(String),
41
42    /// Key generation failed
43    #[error("Key generation failed: {0}")]
44    KeyGenerationFailed(String),
45
46    /// Cryptographic operation failed
47    #[error("Cryptographic operation failed: {0}")]
48    CryptoOperationFailed(String),
49
50    /// Encryption failed
51    #[error("Encryption failed: {0}")]
52    EncryptionError(String),
53
54    /// Decryption failed
55    #[error("Decryption failed: {0}")]
56    DecryptionError(String),
57
58    /// Invalid key handle
59    #[error("Invalid key handle: {0}")]
60    InvalidKeyHandle(String),
61
62    /// Provider not found
63    #[error("Provider not found: {0}")]
64    ProviderNotFound(String),
65
66    /// Provider registration failed
67    #[error("Provider registration failed: {0}")]
68    RegistrationFailed(String),
69
70    /// Configuration error
71    #[error("Configuration error: {0}")]
72    ConfigurationError(String),
73
74    /// I/O error
75    #[error("I/O error: {0}")]
76    IoError(#[from] std::io::Error),
77
78    /// Serialization error
79    #[error("Serialization error: {0}")]
80    SerializationError(#[from] serde_json::Error),
81
82    /// Cryptographic error
83    #[error("Cryptographic error: {0}")]
84    CryptoError(String),
85
86    /// Internal error
87    #[error("Internal error: {0}")]
88    Internal(String),
89}
90
91impl TeeError {
92    /// Creates a new NotAvailable error.
93    pub fn not_available(msg: impl Into<String>) -> Self {
94        TeeError::NotAvailable(msg.into())
95    }
96
97    /// Creates a new AttestationVerificationFailed error.
98    pub fn attestation_failed(msg: impl Into<String>) -> Self {
99        TeeError::AttestationVerificationFailed(msg.into())
100    }
101
102    /// Creates a new Internal error.
103    pub fn internal(msg: impl Into<String>) -> Self {
104        TeeError::Internal(msg.into())
105    }
106}