Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove chrono dependency and use transitive time dependency #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ webpki-roots = "0.26"
pem = "3.0.3"
thiserror = "1.0.31"
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 }
Expand Down
11 changes: 4 additions & 7 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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<EC: Debug = Infallible, EA: Debug = EC> {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<EC: 'static + Debug, EA: 'static + Debug> AcmeState<EC, EA> {
wait: None,
}
}
fn parse_cert(pem: &[u8]) -> Result<(CertifiedKey, [DateTime<Utc>; 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()));
Expand All @@ -203,7 +203,7 @@ impl<EC: 'static + Debug, EA: 'static + Debug> AcmeState<EC, EA> {
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)),
};
Expand All @@ -221,10 +221,7 @@ impl<EC: 'static + Debug, EA: 'static + Debug> AcmeState<EC, EA> {
}
};
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);
Expand Down