summaryrefslogtreecommitdiffstats
path: root/sqv
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-11-20 19:02:34 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-11-21 16:25:30 +0100
commitb251f9e8857fba284f515061ac62013519997e30 (patch)
tree8cb3501b8cb32e43496e56dd76446ba7559c7eed /sqv
parent13c437470cc7377d7b761b5bb9b8d4efb0ba385e (diff)
openpgp: Replace time crate with std::time.
- In sq and sqv, use chrono to interface with the user. - Fixes #341.
Diffstat (limited to 'sqv')
-rw-r--r--sqv/Cargo.toml2
-rw-r--r--sqv/src/sqv.rs32
-rw-r--r--sqv/tests/not-before-after.rs2
3 files changed, 21 insertions, 15 deletions
diff --git a/sqv/Cargo.toml b/sqv/Cargo.toml
index 16375e04..90cad18d 100644
--- a/sqv/Cargo.toml
+++ b/sqv/Cargo.toml
@@ -22,9 +22,9 @@ maintenance = { status = "actively-developed" }
[dependencies]
sequoia-openpgp = { path = "../openpgp", version = "0.11", default-features = false }
+chrono = "0.4"
clap = "2.32.0"
failure = "0.1.2"
-time = "0.1.38"
[build-dependencies]
clap = "2.27.1"
diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs
index db85036c..bf3ce485 100644
--- a/sqv/src/sqv.rs
+++ b/sqv/src/sqv.rs
@@ -6,7 +6,6 @@
extern crate clap;
extern crate failure;
use failure::ResultExt;
-extern crate time;
extern crate sequoia_openpgp as openpgp;
@@ -47,18 +46,25 @@ fn real_main() -> Result<(), failure::Error> {
exit(2);
}
- let not_before = if let Some(t) = matches.value_of("not-before") {
- Some(time::strptime(t, "%Y-%m-%d")
- .context(format!("Bad value passed to --not-before: {:?}", t))?)
- } else {
- None
- };
- let not_after = if let Some(t) = matches.value_of("not-after") {
- Some(time::strptime(t, "%Y-%m-%d")
- .context(format!("Bad value passed to --not-after: {:?}", t))?)
- } else {
- None
- }.unwrap_or_else(|| time::now_utc());
+ use chrono::{DateTime, offset::Utc, NaiveDate};
+ let not_before: Option<std::time::SystemTime> =
+ if let Some(t) = matches.value_of("not-before") {
+ Some(NaiveDate::parse_from_str(t, "%Y-%m-%d")
+ .map(|n| DateTime::<Utc>::from_utc(n.and_hms(0, 0, 0), Utc))
+ .context(format!("Bad value passed to --not-before: {:?}", t))?
+ .into())
+ } else {
+ None
+ };
+ let not_after: std::time::SystemTime =
+ if let Some(t) = matches.value_of("not-after") {
+ Some(NaiveDate::parse_from_str(t, "%Y-%m-%d")
+ .map(|n| DateTime::<Utc>::from_utc(n.and_hms(23, 59, 59), Utc))
+ .context(format!("Bad value passed to --not-after: {:?}", t))?
+ .into())
+ } else {
+ None
+ }.unwrap_or_else(|| std::time::SystemTime::now());
// First, we collect the signatures and the alleged issuers.
// Then, we scan the keyrings exactly once to find the associated
diff --git a/sqv/tests/not-before-after.rs b/sqv/tests/not-before-after.rs
index 1bae9d06..0295dbd9 100644
--- a/sqv/tests/not-before-after.rs
+++ b/sqv/tests/not-before-after.rs
@@ -53,7 +53,7 @@ mod integration {
.with_args(
&["--keyring",
&p("keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp"),
- "--not-after", "2018-08-14",
+ "--not-after", "2018-08-13",
&p("messages/a-cypherpunks-manifesto.txt.ed25519.sig"),
&p("messages/a-cypherpunks-manifesto.txt")])
.fails()