1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, TeeError>;
7
8#[derive(Debug, Error)]
10pub enum TeeError {
11 #[error("TEE hardware not available: {0}")]
13 NotAvailable(String),
14
15 #[error("Failed to generate attestation: {0}")]
17 AttestationGenerationFailed(String),
18
19 #[error("Attestation verification failed: {0}")]
21 AttestationVerificationFailed(String),
22
23 #[error("Invalid attestation report: {0}")]
25 InvalidAttestationReport(String),
26
27 #[error("Certificate chain validation failed: {0}")]
29 CertificateValidationFailed(String),
30
31 #[error("TCB version outdated: current={current}, required={required}")]
33 TcbOutdated {
34 current: String,
35 required: String,
36 },
37
38 #[error("Enclave operation failed: {0}")]
40 EnclaveOperationFailed(String),
41
42 #[error("Key generation failed: {0}")]
44 KeyGenerationFailed(String),
45
46 #[error("Cryptographic operation failed: {0}")]
48 CryptoOperationFailed(String),
49
50 #[error("Encryption failed: {0}")]
52 EncryptionError(String),
53
54 #[error("Decryption failed: {0}")]
56 DecryptionError(String),
57
58 #[error("Invalid key handle: {0}")]
60 InvalidKeyHandle(String),
61
62 #[error("Provider not found: {0}")]
64 ProviderNotFound(String),
65
66 #[error("Provider registration failed: {0}")]
68 RegistrationFailed(String),
69
70 #[error("Configuration error: {0}")]
72 ConfigurationError(String),
73
74 #[error("I/O error: {0}")]
76 IoError(#[from] std::io::Error),
77
78 #[error("Serialization error: {0}")]
80 SerializationError(#[from] serde_json::Error),
81
82 #[error("Cryptographic error: {0}")]
84 CryptoError(String),
85
86 #[error("Internal error: {0}")]
88 Internal(String),
89}
90
91impl TeeError {
92 pub fn not_available(msg: impl Into<String>) -> Self {
94 TeeError::NotAvailable(msg.into())
95 }
96
97 pub fn attestation_failed(msg: impl Into<String>) -> Self {
99 TeeError::AttestationVerificationFailed(msg.into())
100 }
101
102 pub fn internal(msg: impl Into<String>) -> Self {
104 TeeError::Internal(msg.into())
105 }
106}