Skip to content

Commit

Permalink
Merge pull request #7 from benaryorg/dep-update
Browse files Browse the repository at this point in the history
dependency updates
  • Loading branch information
kpcyrd authored Oct 3, 2024
2 parents 1d985b5 + dd7413a commit a045d0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ edition = "2018"

[dependencies]
anyhow = "1.0"
base64 = "0.13"
base64 = "0.21"
lazy_static = "1.4"
log = "0.4"
openssl = "0.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = "0.1"
time = { version = "0.3", features = ["local-offset"] }
time-fmt = "0.3"
time-tz = "1"
ureq = "1"

[dev-dependencies]
doc-comment = "0.3"
env_logger = { version = "0.8", default-features = false }
env_logger = { version = "0.10", default-features = false }
futures = "0.1.25"
hyper = "0.12"
regex = "1.4"
34 changes: 27 additions & 7 deletions src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,29 @@ impl Certificate {
// Display trait produces this format, which is kinda dumb.
// Apr 19 08:48:46 2019 GMT
let expires = parse_date(&not_after)?;
let dur = expires - time::now();
let dur = expires - time::OffsetDateTime::now_utc();

Ok(dur.num_days())
Ok(dur.whole_days())
}
}

fn parse_date(s: &str) -> Result<time::Tm> {
fn parse_date(s: &str) -> Result<time::OffsetDateTime> {
debug!("Parse date/time: {}", s);
let tm = time::strptime(s, "%h %e %H:%M:%S %Y %Z")?;
Ok(tm)
use time_fmt::parse::TimeZoneSpecifier;
use time_tz::{Offset, TimeZone};
let (datetime, zonespecifier) =
time_fmt::parse::parse_date_time_maybe_with_zone("%h %e %H:%M:%S %Y %Z", s)
.context("parsing of date failed")?;
let offset_datetime = match zonespecifier {
Some(TimeZoneSpecifier::Offset(offset)) => datetime.assume_offset(offset),
None => datetime.assume_utc(),
Some(TimeZoneSpecifier::Name(name)) => {
let zone = time_tz::timezones::get_by_name(name)
.ok_or(anyhow::anyhow!("unknown timezone specified"))?;
datetime.assume_offset(zone.get_offset_primary().to_utc())
}
};
Ok(offset_datetime)
}

#[cfg(test)]
Expand All @@ -168,7 +181,14 @@ mod test {

#[test]
fn test_parse_date() {
let x = parse_date("May 3 07:40:15 2019 GMT").unwrap();
assert_eq!(time::strftime("%F %T", &x).unwrap(), "2019-05-03 07:40:15");
let x = parse_date("May 3 07:40:15 2019 GMT")
.context("input date parsing failed")
.unwrap();
assert_eq!(
time_fmt::format::format_offset_date_time("%F %T", x)
.context("date formatting failed")
.unwrap(),
"2019-05-03 07:40:15"
);
}
}
7 changes: 4 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use base64::engine::Engine;
use lazy_static::lazy_static;
use serde::de::DeserializeOwned;

use crate::error::*;
use crate::req::req_safe_read_body;

lazy_static! {
static ref BASE64_CONFIG: base64::Config =
base64::Config::new(base64::CharacterSet::UrlSafe, false);
static ref BASE64_CONFIG: base64::engine::general_purpose::GeneralPurpose =
base64::engine::general_purpose::URL_SAFE;
}

pub(crate) fn base64url<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
base64::encode_config(input, *BASE64_CONFIG)
BASE64_CONFIG.encode(input)
}

pub(crate) fn read_json<T: DeserializeOwned>(res: ureq::Response) -> Result<T> {
Expand Down

0 comments on commit a045d0a

Please sign in to comment.