From 2975190880dfbf6171354259c139383c7c7142e2 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 9 Jan 2022 10:15:59 +0100 Subject: [PATCH] Remove chrono, use time directly, due to RUSTSEC-2020-0159 --- Cargo.toml | 2 +- src/common.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6312f1f..900a37fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ ascii = "1.0" chunked_transfer = "1" openssl = { version = "0.10", optional = true } url = "2" -chrono = { version = "0.4", default-features = false, features=["clock"] } log = "0.4" +time = { version = "0.3", features = [ "std", "formatting" ] } [dev-dependencies] rustc-serialize = "0.3" diff --git a/src/common.rs b/src/common.rs index 8f8265fd..12d06be8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -2,8 +2,7 @@ use ascii::{AsciiStr, AsciiString, FromAsciiError}; use std::cmp::Ordering; use std::fmt::{self, Display, Formatter}; use std::str::FromStr; - -use chrono::*; +use time::{format_description, OffsetDateTime}; /// Status code of a request or response. #[derive(Eq, PartialEq, Copy, Clone, Debug, Ord, PartialOrd)] @@ -398,18 +397,25 @@ impl From<(u8, u8)> for HTTPVersion { /// Represents the current date, expressed in RFC 1123 format, e.g. Sun, 06 Nov 1994 08:49:37 GMT #[allow(clippy::upper_case_acronyms)] pub struct HTTPDate { - d: DateTime, + d: OffsetDateTime, } impl HTTPDate { pub fn new() -> HTTPDate { - HTTPDate { d: Utc::now() } + HTTPDate { + d: OffsetDateTime::now_utc(), + } } } impl ToString for HTTPDate { fn to_string(&self) -> String { - self.d.format("%a, %e %b %Y %H:%M:%S GMT").to_string() + // Note: This can probably be made Self::format however parse is not a const function, making this difficult. + let format = format_description::parse("%a, %e %b %Y %H:%M:%S GMT") + .expect("Cannot fail. The format string is correct."); + self.d + .format(&format) + .expect("Cannot fail with this format under any reasonable conditions.") } }