use serde::{Serialize, Serializer};
use std::path::PathBuf;
use std::time::SystemTime;
#[derive(Debug, Clone, Serialize)]
pub struct LibraryInfo {
pub name: String,
pub path: PathBuf,
pub category: LibraryCategory,
pub library_type: LibraryType,
pub version: Option<String>,
pub vendor: Option<String>,
pub size: u64,
#[serde(serialize_with = "serialize_system_time")]
pub modified: SystemTime,
pub risk_level: RiskLevel,
pub quantum_vulnerable: bool,
}
fn serialize_system_time<S>(time: &SystemTime, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use chrono::{DateTime, Utc};
let datetime = DateTime::<Utc>::from(*time);
serializer.serialize_str(&datetime.to_rfc3339())
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub enum LibraryCategory {
SslTls,
GeneralCrypto,
PostQuantum,
HashFunction,
RustCrypto,
NodeCrypto,
PythonCrypto,
Other,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum LibraryType {
SharedLibrary, StaticLibrary, Manifest, }
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)]
pub enum RiskLevel {
None, Low, Medium, High, Critical, }
impl LibraryCategory {
pub fn icon(&self) -> &'static str {
match self {
LibraryCategory::SslTls => "đ",
LibraryCategory::GeneralCrypto => "đ",
LibraryCategory::PostQuantum => "âī¸",
LibraryCategory::HashFunction => "#ī¸âŖ",
LibraryCategory::RustCrypto => "đĻ",
LibraryCategory::NodeCrypto => "đĻ",
LibraryCategory::PythonCrypto => "đ",
LibraryCategory::Other => "đ",
}
}
pub fn name(&self) -> &'static str {
match self {
LibraryCategory::SslTls => "SSL/TLS",
LibraryCategory::GeneralCrypto => "General Crypto",
LibraryCategory::PostQuantum => "Post-Quantum",
LibraryCategory::HashFunction => "Hash Function",
LibraryCategory::RustCrypto => "Rust Crypto",
LibraryCategory::NodeCrypto => "Node.js Crypto",
LibraryCategory::PythonCrypto => "Python Crypto",
LibraryCategory::Other => "Other",
}
}
}
impl RiskLevel {
pub fn icon(&self) -> &'static str {
match self {
RiskLevel::None => "â
",
RiskLevel::Low => "âšī¸",
RiskLevel::Medium => "â ",
RiskLevel::High => "â ī¸",
RiskLevel::Critical => "đ¨",
}
}
pub fn label(&self) -> &'static str {
match self {
RiskLevel::None => "None",
RiskLevel::Low => "Low",
RiskLevel::Medium => "Medium",
RiskLevel::High => "High",
RiskLevel::Critical => "Critical",
}
}
}