diff --git a/Cargo.toml b/Cargo.toml index a623603..9b6c584 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ webpki-roots = "0.26" pem = "3.0.3" thiserror = "2" x509-parser = "0.16" -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 a69c30a..d49bf41 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; #[allow(clippy::type_complexity)] @@ -191,7 +191,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())); @@ -204,7 +204,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)), }; @@ -224,10 +224,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);