From b6c0961076d4ba5d3731b987b1393a36cb3cde8e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 13 Mar 2024 21:03:15 -0400 Subject: [PATCH] Remove chrono dependency and use transitive time dependency --- Cargo.toml | 2 +- src/state.rs | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b18b09d..acc9838 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ webpki-roots = "0.26" pem = "3.0.3" thiserror = "1.0.31" x509-parser = "0.15.1" -chrono = { version = "0.4.24", default-features = false, features = ["clock"] } +time = "0.3.34" async-trait = "0.1.53" async-io = "2.3.0" tokio = { version= "1.20.1", optional= true } diff --git a/src/state.rs b/src/state.rs index 01b2cc2..940b2cb 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,7 +2,6 @@ use crate::acceptor::AcmeAcceptor; use crate::acme::{Account, AcmeError, Auth, AuthStatus, Directory, Identifier, Order, OrderStatus, ACME_TLS_ALPN_NAME}; use crate::{any_ecdsa_type, crypto_provider, AcmeConfig, Incoming, ResolvesServerCertAcme}; use async_io::Timer; -use chrono::{DateTime, TimeZone, Utc}; use core::fmt; use futures::future::try_join_all; use futures::prelude::*; @@ -20,6 +19,7 @@ use std::sync::Arc; use std::task::{Context, Poll}; use std::time::Duration; use thiserror::Error; +use time::OffsetDateTime; use x509_parser::parse_x509_certificate; pub struct AcmeState { @@ -190,7 +190,7 @@ impl AcmeState { wait: None, } } - fn parse_cert(pem: &[u8]) -> Result<(CertifiedKey, [DateTime; 2]), CertParseError> { + fn parse_cert(pem: &[u8]) -> Result<(CertifiedKey, [OffsetDateTime; 2]), CertParseError> { let mut pems = pem::parse_many(&pem)?; if pems.len() < 2 { return Err(CertParseError::TooFewPem(pems.len())); @@ -203,7 +203,7 @@ impl AcmeState { let validity = match parse_x509_certificate(&cert_chain[0]) { Ok((_, cert)) => { let validity = cert.validity(); - [validity.not_before, validity.not_after].map(|t| Utc.timestamp_opt(t.timestamp(), 0).earliest().unwrap()) + [validity.not_before, validity.not_after].map(|t| t.to_datetime()) } Err(err) => return Err(CertParseError::X509(err)), }; @@ -221,10 +221,7 @@ impl AcmeState { } }; self.resolver.set_cert(Arc::new(cert)); - let wait_duration = (validity[1] - (validity[1] - validity[0]) / 3 - Utc::now()) - .max(chrono::Duration::zero()) - .to_std() - .unwrap_or_default(); + let wait_duration = (validity[1] - (validity[1] - validity[0]) / 3i32 - OffsetDateTime::now_utc()).unsigned_abs(); self.wait = Some(Timer::after(wait_duration)); if cached { return Ok(EventOk::DeployedCachedCert);