syncable_cli/analyzer/vulnerability/
types.rs

1use std::collections::HashMap;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6use crate::analyzer::dependency_parser::Language;
7
8#[derive(Debug, Error)]
9pub enum VulnerabilityError {
10    #[error("Failed to check vulnerabilities: {0}")]
11    CheckFailed(String),
12    
13    #[error("API error: {0}")]
14    ApiError(String),
15    
16    #[error("Command execution failed: {0}")]
17    CommandError(String),
18    
19    #[error("Parse error: {0}")]
20    ParseError(String),
21    
22    #[error("IO error: {0}")]
23    Io(#[from] std::io::Error),
24    
25    #[error("JSON error: {0}")]
26    Json(#[from] serde_json::Error),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct VulnerabilityInfo {
31    pub id: String,
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}