syncable_cli/analyzer/vulnerability/
types.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::analyzer::dependency_parser::Language;
6
7#[derive(Debug, Error)]
8pub enum VulnerabilityError {
9    #[error("Failed to check vulnerabilities: {0}")]
10    CheckFailed(String),
11    
12    #[error("API error: {0}")]
13    ApiError(String),
14    
15    #[error("Command execution failed: {0}")]
16    CommandError(String),
17    
18    #[error("Parse error: {0}")]
19    ParseError(String),
20    
21    #[error("IO error: {0}")]
22    Io(#[from] std::io::Error),
23    
24    #[error("JSON error: {0}")]
25    Json(#[from] serde_json::Error),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct VulnerabilityInfo {
30    pub id: String,
31    pub vuln_type: String,  // New field: "security", "unmaintained", or "yanked"
32    pub severity: VulnerabilitySeverity,
33    pub title: String,
34    pub description: String,
35    pub cve: Option<String>,
36    pub ghsa: Option<String>,
37    pub affected_versions: String,
38    pub patched_versions: Option<String>,
39    pub published_date: Option<DateTime<Utc>>,
40    pub references: Vec<String>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
44pub enum VulnerabilitySeverity {
45    Critical,
46    High,
47    Medium,
48    Low,
49    Info,
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53pub struct VulnerabilityReport {
54    pub checked_at: DateTime<Utc>,
55    pub total_vulnerabilities: usize,
56    pub critical_count: usize,
57    pub high_count: usize,
58    pub medium_count: usize,
59    pub low_count: usize,
60    pub vulnerable_dependencies: Vec<VulnerableDependency>,
61}
62
63#[derive(Debug, Serialize, Deserialize)]
64pub struct VulnerableDependency {
65    pub name: String,
66    pub version: String,
67    pub language: Language,
68    pub vulnerabilities: Vec<VulnerabilityInfo>,
69}