summaryrefslogtreecommitdiffstats
path: root/openpgp/src/lib.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-11-17 12:50:46 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-11-18 14:10:55 +0100
commitb56ea7ab07626ff37e14f0c15c6252b7627a6b72 (patch)
tree595c6a5d11b2db7e9141384a32762052440193ce /openpgp/src/lib.rs
parent991c759dd710bab903baa32dff8dc1fc18e78e3b (diff)
openpgp: Use a WASM-friendly SystemTime::now wrapper.
- Fixes #769.
Diffstat (limited to 'openpgp/src/lib.rs')
-rw-r--r--openpgp/src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs
index f7af0123..a8280d75 100644
--- a/openpgp/src/lib.rs
+++ b/openpgp/src/lib.rs
@@ -104,6 +104,16 @@ fn vec_drain_prefix(v: &mut Vec<u8>, prefix_len: usize) {
}
}
+/// Like std::time::SystemTime::now, but works on WASM.
+fn now() -> std::time::SystemTime {
+ #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
+ chrono::Utc::now().into()
+ }
+ #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
+ std::time::SystemTime::now()
+ }
+}
+
// Like assert!, but checks a pattern.
//
// assert_match!(Some(_) = x);