use thiserror::Error;
pub type Result<T> = std::result::Result<T, SecurityError>;
#[derive(Error, Debug)]
pub enum SecurityError {
#[error("Encryption error: {0}")]
Encryption(String),
#[error("Decryption error: {0}")]
Decryption(String),
#[error("Key management error: {0}")]
KeyManagement(String),
#[error("Key derivation error: {0}")]
KeyDerivation(String),
#[error("Authentication failed: {0}")]
Authentication(String),
#[error("Authorization failed: {0}")]
Authorization(String),
#[error("Access denied: {0}")]
AccessDenied(String),
#[error("Permission denied: {0}")]
PermissionDenied(String),
#[error("Policy evaluation error: {0}")]
PolicyEvaluation(String),
#[error("Role not found: {0}")]
RoleNotFound(String),
#[error("User not found: {0}")]
UserNotFound(String),
#[error("Tenant not found: {0}")]
TenantNotFound(String),
#[error("Tenant isolation violation: {0}")]
TenantIsolationViolation(String),
#[error("Quota exceeded: {0}")]
QuotaExceeded(String),
#[error("Audit logging error: {0}")]
AuditLog(String),
#[error("Audit query error: {0}")]
AuditQuery(String),
#[error("Lineage tracking error: {0}")]
LineageTracking(String),
#[error("Lineage query error: {0}")]
LineageQuery(String),
#[error("Anonymization error: {0}")]
Anonymization(String),
#[error("Compliance violation: {0}")]
ComplianceViolation(String),
#[error("GDPR compliance error: {0}")]
GdprCompliance(String),
#[error("HIPAA compliance error: {0}")]
HipaaCompliance(String),
#[error("FedRAMP compliance error: {0}")]
FedRampCompliance(String),
#[error("Security scanning error: {0}")]
SecurityScan(String),
#[error("Vulnerability detected: {0}")]
VulnerabilityDetected(String),
#[error("Secret detected: {0}")]
SecretDetected(String),
#[error("Malware detected: {0}")]
MalwareDetected(String),
#[error("Invalid configuration: {0}")]
InvalidConfiguration(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Invalid key format: {0}")]
InvalidKeyFormat(String),
#[error("Invalid ciphertext: {0}")]
InvalidCiphertext(String),
#[error("TLS error: {0}")]
Tls(String),
#[error("Certificate error: {0}")]
Certificate(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Deserialization error: {0}")]
Deserialization(String),
#[error("Storage error: {0}")]
Storage(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Internal error: {0}")]
Internal(String),
}
impl SecurityError {
pub fn encryption<S: Into<String>>(msg: S) -> Self {
SecurityError::Encryption(msg.into())
}
pub fn decryption<S: Into<String>>(msg: S) -> Self {
SecurityError::Decryption(msg.into())
}
pub fn key_management<S: Into<String>>(msg: S) -> Self {
SecurityError::KeyManagement(msg.into())
}
pub fn key_derivation<S: Into<String>>(msg: S) -> Self {
SecurityError::KeyDerivation(msg.into())
}
pub fn authentication<S: Into<String>>(msg: S) -> Self {
SecurityError::Authentication(msg.into())
}
pub fn authorization<S: Into<String>>(msg: S) -> Self {
SecurityError::Authorization(msg.into())
}
pub fn access_denied<S: Into<String>>(msg: S) -> Self {
SecurityError::AccessDenied(msg.into())
}
pub fn permission_denied<S: Into<String>>(msg: S) -> Self {
SecurityError::PermissionDenied(msg.into())
}
pub fn internal<S: Into<String>>(msg: S) -> Self {
SecurityError::Internal(msg.into())
}
pub fn tenant_not_found<S: Into<String>>(msg: S) -> Self {
SecurityError::TenantNotFound(msg.into())
}
pub fn quota_exceeded<S: Into<String>>(msg: S) -> Self {
SecurityError::QuotaExceeded(msg.into())
}
pub fn lineage_tracking<S: Into<String>>(msg: S) -> Self {
SecurityError::LineageTracking(msg.into())
}
pub fn lineage_query<S: Into<String>>(msg: S) -> Self {
SecurityError::LineageQuery(msg.into())
}
pub fn audit_log<S: Into<String>>(msg: S) -> Self {
SecurityError::AuditLog(msg.into())
}
pub fn audit_query<S: Into<String>>(msg: S) -> Self {
SecurityError::AuditQuery(msg.into())
}
pub fn policy_evaluation<S: Into<String>>(msg: S) -> Self {
SecurityError::PolicyEvaluation(msg.into())
}
pub fn role_not_found<S: Into<String>>(msg: S) -> Self {
SecurityError::RoleNotFound(msg.into())
}
pub fn user_not_found<S: Into<String>>(msg: S) -> Self {
SecurityError::UserNotFound(msg.into())
}
pub fn anonymization<S: Into<String>>(msg: S) -> Self {
SecurityError::Anonymization(msg.into())
}
pub fn compliance_violation<S: Into<String>>(msg: S) -> Self {
SecurityError::ComplianceViolation(msg.into())
}
pub fn invalid_input<S: Into<String>>(msg: S) -> Self {
SecurityError::InvalidInput(msg.into())
}
pub fn serialization<S: Into<String>>(msg: S) -> Self {
SecurityError::Serialization(msg.into())
}
pub fn deserialization<S: Into<String>>(msg: S) -> Self {
SecurityError::Deserialization(msg.into())
}
pub fn certificate<S: Into<String>>(msg: S) -> Self {
SecurityError::Certificate(msg.into())
}
pub fn tls<S: Into<String>>(msg: S) -> Self {
SecurityError::Tls(msg.into())
}
pub fn storage<S: Into<String>>(msg: S) -> Self {
SecurityError::Storage(msg.into())
}
pub fn invalid_configuration<S: Into<String>>(msg: S) -> Self {
SecurityError::InvalidConfiguration(msg.into())
}
pub fn invalid_key_format<S: Into<String>>(msg: S) -> Self {
SecurityError::InvalidKeyFormat(msg.into())
}
pub fn invalid_ciphertext<S: Into<String>>(msg: S) -> Self {
SecurityError::InvalidCiphertext(msg.into())
}
pub fn tenant_isolation_violation<S: Into<String>>(msg: S) -> Self {
SecurityError::TenantIsolationViolation(msg.into())
}
pub fn gdpr_compliance<S: Into<String>>(msg: S) -> Self {
SecurityError::GdprCompliance(msg.into())
}
pub fn hipaa_compliance<S: Into<String>>(msg: S) -> Self {
SecurityError::HipaaCompliance(msg.into())
}
pub fn fedramp_compliance<S: Into<String>>(msg: S) -> Self {
SecurityError::FedRampCompliance(msg.into())
}
pub fn security_scan<S: Into<String>>(msg: S) -> Self {
SecurityError::SecurityScan(msg.into())
}
pub fn vulnerability_detected<S: Into<String>>(msg: S) -> Self {
SecurityError::VulnerabilityDetected(msg.into())
}
pub fn secret_detected<S: Into<String>>(msg: S) -> Self {
SecurityError::SecretDetected(msg.into())
}
pub fn malware_detected<S: Into<String>>(msg: S) -> Self {
SecurityError::MalwareDetected(msg.into())
}
}