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 severity: VulnerabilitySeverity,
32    pub title: String,
33    pub description: String,
34    pub cve: Option<String>,
35    pub ghsa: Option<String>,
36    pub affected_versions: String,
37    pub patched_versions: Option<String>,
38    pub published_date: Option<DateTime<Utc>>,
39    pub references: Vec<String>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
43pub enum VulnerabilitySeverity {
44    Critical,
45    High,
46    Medium,
47    Low,
48    Info,
49}
50
51#[derive(Debug, Serialize, Deserialize)]
52pub struct VulnerabilityReport {
53    pub checked_at: DateTime<Utc>,
54    pub total_vulnerabilities: usize,
55    pub critical_count: usize,
56    pub high_count: usize,
57    pub medium_count: usize,
58    pub low_count: usize,
59    pub vulnerable_dependencies: Vec<VulnerableDependency>,
60}
61
62#[derive(Debug, Serialize, Deserialize)]
63pub struct VulnerableDependency {
64    pub name: String,
65    pub version: String,
66    pub language: Language,
67    pub vulnerabilities: Vec<VulnerabilityInfo>,
68}