oxigdal_security/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, SecurityError>;
7
8#[derive(Error, Debug)]
10pub enum SecurityError {
11 #[error("Encryption error: {0}")]
13 Encryption(String),
14
15 #[error("Decryption error: {0}")]
17 Decryption(String),
18
19 #[error("Key management error: {0}")]
21 KeyManagement(String),
22
23 #[error("Key derivation error: {0}")]
25 KeyDerivation(String),
26
27 #[error("Authentication failed: {0}")]
29 Authentication(String),
30
31 #[error("Authorization failed: {0}")]
33 Authorization(String),
34
35 #[error("Access denied: {0}")]
37 AccessDenied(String),
38
39 #[error("Permission denied: {0}")]
41 PermissionDenied(String),
42
43 #[error("Policy evaluation error: {0}")]
45 PolicyEvaluation(String),
46
47 #[error("Role not found: {0}")]
49 RoleNotFound(String),
50
51 #[error("User not found: {0}")]
53 UserNotFound(String),
54
55 #[error("Tenant not found: {0}")]
57 TenantNotFound(String),
58
59 #[error("Tenant isolation violation: {0}")]
61 TenantIsolationViolation(String),
62
63 #[error("Quota exceeded: {0}")]
65 QuotaExceeded(String),
66
67 #[error("Audit logging error: {0}")]
69 AuditLog(String),
70
71 #[error("Audit query error: {0}")]
73 AuditQuery(String),
74
75 #[error("Lineage tracking error: {0}")]
77 LineageTracking(String),
78
79 #[error("Lineage query error: {0}")]
81 LineageQuery(String),
82
83 #[error("Anonymization error: {0}")]
85 Anonymization(String),
86
87 #[error("Compliance violation: {0}")]
89 ComplianceViolation(String),
90
91 #[error("GDPR compliance error: {0}")]
93 GdprCompliance(String),
94
95 #[error("HIPAA compliance error: {0}")]
97 HipaaCompliance(String),
98
99 #[error("FedRAMP compliance error: {0}")]
101 FedRampCompliance(String),
102
103 #[error("Security scanning error: {0}")]
105 SecurityScan(String),
106
107 #[error("Vulnerability detected: {0}")]
109 VulnerabilityDetected(String),
110
111 #[error("Secret detected: {0}")]
113 SecretDetected(String),
114
115 #[error("Malware detected: {0}")]
117 MalwareDetected(String),
118
119 #[error("Invalid configuration: {0}")]
121 InvalidConfiguration(String),
122
123 #[error("Invalid input: {0}")]
125 InvalidInput(String),
126
127 #[error("Invalid key format: {0}")]
129 InvalidKeyFormat(String),
130
131 #[error("Invalid ciphertext: {0}")]
133 InvalidCiphertext(String),
134
135 #[error("TLS error: {0}")]
137 Tls(String),
138
139 #[error("Certificate error: {0}")]
141 Certificate(String),
142
143 #[error("Serialization error: {0}")]
145 Serialization(String),
146
147 #[error("Deserialization error: {0}")]
149 Deserialization(String),
150
151 #[error("Storage error: {0}")]
153 Storage(String),
154
155 #[error("I/O error: {0}")]
157 Io(#[from] std::io::Error),
158
159 #[error("JSON error: {0}")]
161 Json(#[from] serde_json::Error),
162
163 #[error("Internal error: {0}")]
165 Internal(String),
166}
167
168impl SecurityError {
169 pub fn encryption<S: Into<String>>(msg: S) -> Self {
171 SecurityError::Encryption(msg.into())
172 }
173
174 pub fn decryption<S: Into<String>>(msg: S) -> Self {
176 SecurityError::Decryption(msg.into())
177 }
178
179 pub fn key_management<S: Into<String>>(msg: S) -> Self {
181 SecurityError::KeyManagement(msg.into())
182 }
183
184 pub fn key_derivation<S: Into<String>>(msg: S) -> Self {
186 SecurityError::KeyDerivation(msg.into())
187 }
188
189 pub fn authentication<S: Into<String>>(msg: S) -> Self {
191 SecurityError::Authentication(msg.into())
192 }
193
194 pub fn authorization<S: Into<String>>(msg: S) -> Self {
196 SecurityError::Authorization(msg.into())
197 }
198
199 pub fn access_denied<S: Into<String>>(msg: S) -> Self {
201 SecurityError::AccessDenied(msg.into())
202 }
203
204 pub fn permission_denied<S: Into<String>>(msg: S) -> Self {
206 SecurityError::PermissionDenied(msg.into())
207 }
208
209 pub fn internal<S: Into<String>>(msg: S) -> Self {
211 SecurityError::Internal(msg.into())
212 }
213
214 pub fn tenant_not_found<S: Into<String>>(msg: S) -> Self {
216 SecurityError::TenantNotFound(msg.into())
217 }
218
219 pub fn quota_exceeded<S: Into<String>>(msg: S) -> Self {
221 SecurityError::QuotaExceeded(msg.into())
222 }
223
224 pub fn lineage_tracking<S: Into<String>>(msg: S) -> Self {
226 SecurityError::LineageTracking(msg.into())
227 }
228
229 pub fn lineage_query<S: Into<String>>(msg: S) -> Self {
231 SecurityError::LineageQuery(msg.into())
232 }
233
234 pub fn audit_log<S: Into<String>>(msg: S) -> Self {
236 SecurityError::AuditLog(msg.into())
237 }
238
239 pub fn audit_query<S: Into<String>>(msg: S) -> Self {
241 SecurityError::AuditQuery(msg.into())
242 }
243
244 pub fn policy_evaluation<S: Into<String>>(msg: S) -> Self {
246 SecurityError::PolicyEvaluation(msg.into())
247 }
248
249 pub fn role_not_found<S: Into<String>>(msg: S) -> Self {
251 SecurityError::RoleNotFound(msg.into())
252 }
253
254 pub fn user_not_found<S: Into<String>>(msg: S) -> Self {
256 SecurityError::UserNotFound(msg.into())
257 }
258
259 pub fn anonymization<S: Into<String>>(msg: S) -> Self {
261 SecurityError::Anonymization(msg.into())
262 }
263
264 pub fn compliance_violation<S: Into<String>>(msg: S) -> Self {
266 SecurityError::ComplianceViolation(msg.into())
267 }
268
269 pub fn invalid_input<S: Into<String>>(msg: S) -> Self {
271 SecurityError::InvalidInput(msg.into())
272 }
273
274 pub fn serialization<S: Into<String>>(msg: S) -> Self {
276 SecurityError::Serialization(msg.into())
277 }
278
279 pub fn deserialization<S: Into<String>>(msg: S) -> Self {
281 SecurityError::Deserialization(msg.into())
282 }
283
284 pub fn certificate<S: Into<String>>(msg: S) -> Self {
286 SecurityError::Certificate(msg.into())
287 }
288
289 pub fn tls<S: Into<String>>(msg: S) -> Self {
291 SecurityError::Tls(msg.into())
292 }
293
294 pub fn storage<S: Into<String>>(msg: S) -> Self {
296 SecurityError::Storage(msg.into())
297 }
298
299 pub fn invalid_configuration<S: Into<String>>(msg: S) -> Self {
301 SecurityError::InvalidConfiguration(msg.into())
302 }
303
304 pub fn invalid_key_format<S: Into<String>>(msg: S) -> Self {
306 SecurityError::InvalidKeyFormat(msg.into())
307 }
308
309 pub fn invalid_ciphertext<S: Into<String>>(msg: S) -> Self {
311 SecurityError::InvalidCiphertext(msg.into())
312 }
313
314 pub fn tenant_isolation_violation<S: Into<String>>(msg: S) -> Self {
316 SecurityError::TenantIsolationViolation(msg.into())
317 }
318
319 pub fn gdpr_compliance<S: Into<String>>(msg: S) -> Self {
321 SecurityError::GdprCompliance(msg.into())
322 }
323
324 pub fn hipaa_compliance<S: Into<String>>(msg: S) -> Self {
326 SecurityError::HipaaCompliance(msg.into())
327 }
328
329 pub fn fedramp_compliance<S: Into<String>>(msg: S) -> Self {
331 SecurityError::FedRampCompliance(msg.into())
332 }
333
334 pub fn security_scan<S: Into<String>>(msg: S) -> Self {
336 SecurityError::SecurityScan(msg.into())
337 }
338
339 pub fn vulnerability_detected<S: Into<String>>(msg: S) -> Self {
341 SecurityError::VulnerabilityDetected(msg.into())
342 }
343
344 pub fn secret_detected<S: Into<String>>(msg: S) -> Self {
346 SecurityError::SecretDetected(msg.into())
347 }
348
349 pub fn malware_detected<S: Into<String>>(msg: S) -> Self {
351 SecurityError::MalwareDetected(msg.into())
352 }
353}