From b56ea7ab07626ff37e14f0c15c6252b7627a6b72 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 17 Nov 2021 12:50:46 +0100 Subject: openpgp: Use a WASM-friendly SystemTime::now wrapper. - Fixes #769. --- openpgp/src/packet/key.rs | 6 +++--- openpgp/src/packet/signature.rs | 6 +++--- openpgp/src/packet/signature/subpacket.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'openpgp/src/packet') diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 07fc9d2d..6e75c604 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -952,7 +952,7 @@ impl Key4 point.insert(0, 0x40); Self::new( - ctime.into().unwrap_or_else(time::SystemTime::now), + ctime.into().unwrap_or_else(crate::now), PublicKeyAlgorithm::ECDH, mpi::PublicKey::ECDH { curve: Curve::Cv25519, @@ -976,7 +976,7 @@ impl Key4 point.insert(0, 0x40); Self::new( - ctime.into().unwrap_or_else(time::SystemTime::now), + ctime.into().unwrap_or_else(crate::now), PublicKeyAlgorithm::EdDSA, mpi::PublicKey::EdDSA { curve: Curve::Ed25519, @@ -994,7 +994,7 @@ impl Key4 -> Result where T: Into> { Self::new( - ctime.into().unwrap_or_else(time::SystemTime::now), + ctime.into().unwrap_or_else(crate::now), PublicKeyAlgorithm::RSAEncryptSign, mpi::PublicKey::RSA { e: mpi::MPI::new(e), diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index aa19c130..e8d81904 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -1607,10 +1607,10 @@ impl SignatureBuilder { if let Some(oct) = self.original_creation_time { let t = (oct + time::Duration::new(1, 0)).max( - time::SystemTime::now() - + crate::now() - time::Duration::new(SIG_BACKDATE_BY, 0)); - if t > time::SystemTime::now() { + if t > crate::now() { return Err(Error::InvalidOperation( "Cannot create valid signature newer than template" .into()).into()); @@ -1618,7 +1618,7 @@ impl SignatureBuilder { self.set_signature_creation_time(t)? } else { - self.set_signature_creation_time(time::SystemTime::now())? + self.set_signature_creation_time(crate::now())? }; } diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index f8a5873a..e26375bd 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -2500,10 +2500,10 @@ impl SubpacketAreas { let (time, tolerance) = match (time.into(), clock_skew_tolerance.into()) { (None, None) => - (time::SystemTime::now(), + (crate::now(), *CLOCK_SKEW_TOLERANCE), (None, Some(tolerance)) => - (time::SystemTime::now(), + (crate::now(), tolerance), (Some(time), None) => (time, time::Duration::new(0, 0)), @@ -2695,7 +2695,7 @@ impl SubpacketAreas { R: key::KeyRole, T: Into> { - let t = t.into().unwrap_or_else(time::SystemTime::now); + let t = t.into().unwrap_or_else(crate::now); match self.key_validity_period() { Some(e) if e.as_secs() > 0 && key.creation_time() + e <= t => @@ -7028,7 +7028,7 @@ fn accessors() { // Cook up a timestamp without ns resolution. use std::convert::TryFrom; let now: time::SystemTime = - Timestamp::try_from(time::SystemTime::now()).unwrap().into(); + Timestamp::try_from(crate::now()).unwrap().into(); sig = sig.set_signature_creation_time(now).unwrap(); let sig_ = -- cgit v1.2.3