Skip to main content

oxigdal_security/
error.rs

1//! Error types for the security crate.
2
3use thiserror::Error;
4
5/// Result type for security operations.
6pub type Result<T> = std::result::Result<T, SecurityError>;
7
8/// Errors that can occur in security operations.
9#[derive(Error, Debug)]
10pub enum SecurityError {
11    /// Encryption operation failed.
12    #[error("Encryption error: {0}")]
13    Encryption(String),
14
15    /// Decryption operation failed.
16    #[error("Decryption error: {0}")]
17    Decryption(String),
18
19    /// Key management error.
20    #[error("Key management error: {0}")]
21    KeyManagement(String),
22
23    /// Key derivation error.
24    #[error("Key derivation error: {0}")]
25    KeyDerivation(String),
26
27    /// Authentication failed.
28    #[error("Authentication failed: {0}")]
29    Authentication(String),
30
31    /// Authorization failed.
32    #[error("Authorization failed: {0}")]
33    Authorization(String),
34
35    /// Access denied.
36    #[error("Access denied: {0}")]
37    AccessDenied(String),
38
39    /// Permission denied.
40    #[error("Permission denied: {0}")]
41    PermissionDenied(String),
42
43    /// Policy evaluation failed.
44    #[error("Policy evaluation error: {0}")]
45    PolicyEvaluation(String),
46
47    /// Role not found.
48    #[error("Role not found: {0}")]
49    RoleNotFound(String),
50
51    /// User not found.
52    #[error("User not found: {0}")]
53    UserNotFound(String),
54
55    /// Tenant not found.
56    #[error("Tenant not found: {0}")]
57    TenantNotFound(String),
58
59    /// Tenant isolation violation.
60    #[error("Tenant isolation violation: {0}")]
61    TenantIsolationViolation(String),
62
63    /// Quota exceeded.
64    #[error("Quota exceeded: {0}")]
65    QuotaExceeded(String),
66
67    /// Audit logging error.
68    #[error("Audit logging error: {0}")]
69    AuditLog(String),
70
71    /// Audit query error.
72    #[error("Audit query error: {0}")]
73    AuditQuery(String),
74
75    /// Lineage tracking error.
76    #[error("Lineage tracking error: {0}")]
77    LineageTracking(String),
78
79    /// Lineage query error.
80    #[error("Lineage query error: {0}")]
81    LineageQuery(String),
82
83    /// Anonymization error.
84    #[error("Anonymization error: {0}")]
85    Anonymization(String),
86
87    /// Compliance violation.
88    #[error("Compliance violation: {0}")]
89    ComplianceViolation(String),
90
91    /// GDPR compliance error.
92    #[error("GDPR compliance error: {0}")]
93    GdprCompliance(String),
94
95    /// HIPAA compliance error.
96    #[error("HIPAA compliance error: {0}")]
97    HipaaCompliance(String),
98
99    /// FedRAMP compliance error.
100    #[error("FedRAMP compliance error: {0}")]
101    FedRampCompliance(String),
102
103    /// Security scanning error.
104    #[error("Security scanning error: {0}")]
105    SecurityScan(String),
106
107    /// Vulnerability detected.
108    #[error("Vulnerability detected: {0}")]
109    VulnerabilityDetected(String),
110
111    /// Secret detected in data.
112    #[error("Secret detected: {0}")]
113    SecretDetected(String),
114
115    /// Malware detected.
116    #[error("Malware detected: {0}")]
117    MalwareDetected(String),
118
119    /// Invalid configuration.
120    #[error("Invalid configuration: {0}")]
121    InvalidConfiguration(String),
122
123    /// Invalid input.
124    #[error("Invalid input: {0}")]
125    InvalidInput(String),
126
127    /// Invalid key format.
128    #[error("Invalid key format: {0}")]
129    InvalidKeyFormat(String),
130
131    /// Invalid ciphertext.
132    #[error("Invalid ciphertext: {0}")]
133    InvalidCiphertext(String),
134
135    /// TLS error.
136    #[error("TLS error: {0}")]
137    Tls(String),
138
139    /// Certificate error.
140    #[error("Certificate error: {0}")]
141    Certificate(String),
142
143    /// Serialization error.
144    #[error("Serialization error: {0}")]
145    Serialization(String),
146
147    /// Deserialization error.
148    #[error("Deserialization error: {0}")]
149    Deserialization(String),
150
151    /// Storage error.
152    #[error("Storage error: {0}")]
153    Storage(String),
154
155    /// I/O error.
156    #[error("I/O error: {0}")]
157    Io(#[from] std::io::Error),
158
159    /// JSON error.
160    #[error("JSON error: {0}")]
161    Json(#[from] serde_json::Error),
162
163    /// Internal error.
164    #[error("Internal error: {0}")]
165    Internal(String),
166}
167
168impl SecurityError {
169    /// Create a new encryption error.
170    pub fn encryption<S: Into<String>>(msg: S) -> Self {
171        SecurityError::Encryption(msg.into())
172    }
173
174    /// Create a new decryption error.
175    pub fn decryption<S: Into<String>>(msg: S) -> Self {
176        SecurityError::Decryption(msg.into())
177    }
178
179    /// Create a new key management error.
180    pub fn key_management<S: Into<String>>(msg: S) -> Self {
181        SecurityError::KeyManagement(msg.into())
182    }
183
184    /// Create a new key derivation error.
185    pub fn key_derivation<S: Into<String>>(msg: S) -> Self {
186        SecurityError::KeyDerivation(msg.into())
187    }
188
189    /// Create a new authentication error.
190    pub fn authentication<S: Into<String>>(msg: S) -> Self {
191        SecurityError::Authentication(msg.into())
192    }
193
194    /// Create a new authorization error.
195    pub fn authorization<S: Into<String>>(msg: S) -> Self {
196        SecurityError::Authorization(msg.into())
197    }
198
199    /// Create a new access denied error.
200    pub fn access_denied<S: Into<String>>(msg: S) -> Self {
201        SecurityError::AccessDenied(msg.into())
202    }
203
204    /// Create a new permission denied error.
205    pub fn permission_denied<S: Into<String>>(msg: S) -> Self {
206        SecurityError::PermissionDenied(msg.into())
207    }
208
209    /// Create a new internal error.
210    pub fn internal<S: Into<String>>(msg: S) -> Self {
211        SecurityError::Internal(msg.into())
212    }
213
214    /// Create a new tenant not found error.
215    pub fn tenant_not_found<S: Into<String>>(msg: S) -> Self {
216        SecurityError::TenantNotFound(msg.into())
217    }
218
219    /// Create a new quota exceeded error.
220    pub fn quota_exceeded<S: Into<String>>(msg: S) -> Self {
221        SecurityError::QuotaExceeded(msg.into())
222    }
223
224    /// Create a new lineage tracking error.
225    pub fn lineage_tracking<S: Into<String>>(msg: S) -> Self {
226        SecurityError::LineageTracking(msg.into())
227    }
228
229    /// Create a new lineage query error.
230    pub fn lineage_query<S: Into<String>>(msg: S) -> Self {
231        SecurityError::LineageQuery(msg.into())
232    }
233
234    /// Create a new audit log error.
235    pub fn audit_log<S: Into<String>>(msg: S) -> Self {
236        SecurityError::AuditLog(msg.into())
237    }
238
239    /// Create a new audit query error.
240    pub fn audit_query<S: Into<String>>(msg: S) -> Self {
241        SecurityError::AuditQuery(msg.into())
242    }
243
244    /// Create a new policy evaluation error.
245    pub fn policy_evaluation<S: Into<String>>(msg: S) -> Self {
246        SecurityError::PolicyEvaluation(msg.into())
247    }
248
249    /// Create a new role not found error.
250    pub fn role_not_found<S: Into<String>>(msg: S) -> Self {
251        SecurityError::RoleNotFound(msg.into())
252    }
253
254    /// Create a new user not found error.
255    pub fn user_not_found<S: Into<String>>(msg: S) -> Self {
256        SecurityError::UserNotFound(msg.into())
257    }
258
259    /// Create a new anonymization error.
260    pub fn anonymization<S: Into<String>>(msg: S) -> Self {
261        SecurityError::Anonymization(msg.into())
262    }
263
264    /// Create a new compliance violation error.
265    pub fn compliance_violation<S: Into<String>>(msg: S) -> Self {
266        SecurityError::ComplianceViolation(msg.into())
267    }
268
269    /// Create a new invalid input error.
270    pub fn invalid_input<S: Into<String>>(msg: S) -> Self {
271        SecurityError::InvalidInput(msg.into())
272    }
273
274    /// Create a new serialization error.
275    pub fn serialization<S: Into<String>>(msg: S) -> Self {
276        SecurityError::Serialization(msg.into())
277    }
278
279    /// Create a new deserialization error.
280    pub fn deserialization<S: Into<String>>(msg: S) -> Self {
281        SecurityError::Deserialization(msg.into())
282    }
283
284    /// Create a new certificate error.
285    pub fn certificate<S: Into<String>>(msg: S) -> Self {
286        SecurityError::Certificate(msg.into())
287    }
288
289    /// Create a new TLS error.
290    pub fn tls<S: Into<String>>(msg: S) -> Self {
291        SecurityError::Tls(msg.into())
292    }
293
294    /// Create a new storage error.
295    pub fn storage<S: Into<String>>(msg: S) -> Self {
296        SecurityError::Storage(msg.into())
297    }
298
299    /// Create a new invalid configuration error.
300    pub fn invalid_configuration<S: Into<String>>(msg: S) -> Self {
301        SecurityError::InvalidConfiguration(msg.into())
302    }
303
304    /// Create a new invalid key format error.
305    pub fn invalid_key_format<S: Into<String>>(msg: S) -> Self {
306        SecurityError::InvalidKeyFormat(msg.into())
307    }
308
309    /// Create a new invalid ciphertext error.
310    pub fn invalid_ciphertext<S: Into<String>>(msg: S) -> Self {
311        SecurityError::InvalidCiphertext(msg.into())
312    }
313
314    /// Create a new tenant isolation violation error.
315    pub fn tenant_isolation_violation<S: Into<String>>(msg: S) -> Self {
316        SecurityError::TenantIsolationViolation(msg.into())
317    }
318
319    /// Create a new GDPR compliance error.
320    pub fn gdpr_compliance<S: Into<String>>(msg: S) -> Self {
321        SecurityError::GdprCompliance(msg.into())
322    }
323
324    /// Create a new HIPAA compliance error.
325    pub fn hipaa_compliance<S: Into<String>>(msg: S) -> Self {
326        SecurityError::HipaaCompliance(msg.into())
327    }
328
329    /// Create a new FedRAMP compliance error.
330    pub fn fedramp_compliance<S: Into<String>>(msg: S) -> Self {
331        SecurityError::FedRampCompliance(msg.into())
332    }
333
334    /// Create a new security scan error.
335    pub fn security_scan<S: Into<String>>(msg: S) -> Self {
336        SecurityError::SecurityScan(msg.into())
337    }
338
339    /// Create a new vulnerability detected error.
340    pub fn vulnerability_detected<S: Into<String>>(msg: S) -> Self {
341        SecurityError::VulnerabilityDetected(msg.into())
342    }
343
344    /// Create a new secret detected error.
345    pub fn secret_detected<S: Into<String>>(msg: S) -> Self {
346        SecurityError::SecretDetected(msg.into())
347    }
348
349    /// Create a new malware detected error.
350    pub fn malware_detected<S: Into<String>>(msg: S) -> Self {
351        SecurityError::MalwareDetected(msg.into())
352    }
353}