use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SecuritySeverity {
Critical,
High,
Medium,
Low,
Info,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum SecurityCategory {
SecretsExposure,
InsecureConfiguration,
CodeSecurityPattern,
InfrastructureSecurity,
AuthenticationSecurity,
DataProtection,
NetworkSecurity,
Compliance,
CodeInjection,
CommandInjection,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityFinding {
pub id: String,
pub title: String,
pub description: String,
pub severity: SecuritySeverity,
pub category: SecurityCategory,
pub file_path: Option<PathBuf>,
pub line_number: Option<usize>,
pub column_number: Option<usize>,
pub evidence: Option<String>,
pub remediation: Vec<String>,
pub references: Vec<String>,
pub cwe_id: Option<String>,
pub compliance_frameworks: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SecurityReport {
pub analyzed_at: chrono::DateTime<chrono::Utc>,
pub overall_score: f32, pub risk_level: SecuritySeverity,
pub total_findings: usize,
pub findings_by_severity: HashMap<SecuritySeverity, usize>,
pub findings_by_category: HashMap<SecurityCategory, usize>,
pub findings: Vec<SecurityFinding>,
pub recommendations: Vec<String>,
pub compliance_status: HashMap<String, ComplianceStatus>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplianceStatus {
pub framework: String,
pub coverage: f32, pub missing_controls: Vec<String>,
pub recommendations: Vec<String>,
}
pub trait SecurityAnalyzer {
type Config;
type Error: std::error::Error;
fn analyze_project(
&self,
project_root: &std::path::Path,
) -> Result<SecurityReport, Self::Error>;
fn config(&self) -> &Self::Config;
fn supported_extensions(&self) -> Vec<&'static str>;
}