#[cfg(feature = "chrono")]
use chrono::{Date as ChronoDate, DateTime, Utc};
use semver::VersionReq;
use std::fmt;
use error::Error;
use package::PackageName;
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Advisory {
pub id: AdvisoryId,
pub package: PackageName,
pub patched_versions: Vec<VersionReq>,
#[serde(default)]
pub unaffected_versions: Vec<VersionReq>,
#[serde(default)]
pub aliases: Vec<AdvisoryId>,
#[serde(default)]
pub references: Vec<AdvisoryId>,
pub date: Date,
pub url: Option<String>,
pub title: String,
pub description: String,
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize)]
pub struct AdvisoryId(pub String);
impl AsRef<str> for AdvisoryId {
fn as_ref(&self) -> &str {
&self.0
}
}
impl fmt::Display for AdvisoryId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl<'a> From<&'a str> for AdvisoryId {
fn from(string: &'a str) -> AdvisoryId {
AdvisoryId(string.into())
}
}
impl Into<String> for AdvisoryId {
fn into(self) -> String {
self.0
}
}
#[derive(Serialize, Deserialize)]
pub(crate) struct AdvisoryWrapper {
pub(crate) advisory: Advisory,
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize)]
pub struct Date(pub String);
impl Date {
#[cfg(feature = "chrono")]
pub fn into_chrono_date(&self) -> Result<ChronoDate<Utc>, Error> {
let datetime = DateTime::parse_from_rfc3339(self.0.as_ref())?;
Ok(ChronoDate::from_utc(datetime.naive_utc().date(), Utc))
}
}
impl Into<String> for Date {
fn into(self) -> String {
self.0
}
}
impl<'a> From<&'a str> for Date {
fn from(string: &'a str) -> Date {
Date(string.into())
}
}