cipherrun 0.3.0

A fast, modular, and scalable TLS/SSL security scanner written in Rust
// Vulnerability Record Model
// Represents detected vulnerabilities during a scan

use serde::{Deserialize, Serialize};
use sqlx::FromRow;

/// Vulnerability record in database
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct VulnerabilityRecord {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vuln_id: Option<i64>,
    pub scan_id: i64,
    pub vulnerability_type: String, // "Heartbleed", "POODLE", etc.
    pub severity: String,           // "critical", "high", "medium", "low", "info"
    pub description: Option<String>,
    pub cve_id: Option<String>,
    pub affected_component: Option<String>,
}

impl VulnerabilityRecord {
    /// Create new vulnerability record
    pub fn new(scan_id: i64, vulnerability_type: String, severity: String) -> Self {
        Self {
            vuln_id: None,
            scan_id,
            vulnerability_type,
            severity,
            description: None,
            cve_id: None,
            affected_component: None,
        }
    }

    /// Set description
    pub fn with_description(mut self, description: String) -> Self {
        self.description = Some(description);
        self
    }

    /// Set CVE ID
    pub fn with_cve(mut self, cve_id: String) -> Self {
        self.cve_id = Some(cve_id);
        self
    }

    /// Set affected component
    pub fn with_component(mut self, component: String) -> Self {
        self.affected_component = Some(component);
        self
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_vulnerability_record_creation() {
        let vuln = VulnerabilityRecord::new(1, "Heartbleed".to_string(), "critical".to_string())
            .with_cve("CVE-2014-0160".to_string())
            .with_description("OpenSSL heartbeat vulnerability".to_string());

        assert_eq!(vuln.scan_id, 1);
        assert_eq!(vuln.vulnerability_type, "Heartbleed");
        assert_eq!(vuln.severity, "critical");
        assert_eq!(vuln.cve_id, Some("CVE-2014-0160".to_string()));
    }
}