1use crate::AdvisoryType;
2use chrono::{DateTime, Utc};
3use serde::Serialize;
4
5#[derive(Debug, Clone, Serialize)]
6pub struct TargetWithAdvisory {
7 pub name: Option<String>,
8 pub version: String,
9 pub ecosystem: Option<String>,
10 pub advisory_type: AdvisoryType,
11 pub repository_path: Option<String>,
12 pub advisories: Vec<Advisory>,
13}
14
15#[derive(Debug, Clone, Serialize)]
16pub struct Advisory {
17 pub ghsa_id: String,
18 pub cve_id: Option<String>,
19 pub summary: String,
20 pub description: String,
21 pub severity: Severity,
22 pub cvss_severities: CvssSeverities,
23 pub epss: Option<Epss>,
24 pub html_url: String,
25 pub published_at: DateTime<Utc>,
26 pub updated_at: DateTime<Utc>,
27 pub withdrawn_at: Option<DateTime<Utc>>,
28 pub vulnerabilities: Vec<Vulnerability>,
29}
30
31#[derive(
32 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, strum_macros::Display,
33)]
34pub enum Severity {
35 Unknown,
36 Low,
37 Medium,
38 High,
39 Critical,
40}
41
42impl Severity {
43 pub const fn order(self) -> i32 {
45 match self {
46 Severity::Critical => 1,
47 Severity::High => 2,
48 Severity::Medium => 3,
49 Severity::Low => 4,
50 Severity::Unknown => 5,
51 }
52 }
53}
54
55#[derive(Debug, Clone, Serialize)]
56pub struct Vulnerability {
57 pub package: Package,
58 pub vulnerable_version_range: String,
59 pub patched_versions: Vec<String>,
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
63pub struct Package {
64 pub ecosystem: String,
65 pub name: String,
66}
67
68#[derive(Debug, Clone, Serialize)]
69pub struct CvssSeverities {
70 pub cvss_v3: CvssScore,
71 pub cvss_v4: CvssScore,
72}
73
74#[derive(Debug, Clone, Serialize)]
75pub struct CvssScore {
76 pub vector_string: Option<String>,
77 pub score: Option<f64>,
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
81pub struct Epss {
82 pub percentage: f64,
83 pub percentile: f64,
84}