diff options
Diffstat (limited to 'crates/tor-checkable')
| -rw-r--r-- | crates/tor-checkable/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/tor-checkable/src/lib.rs | 3 | ||||
| -rw-r--r-- | crates/tor-checkable/src/timed.rs | 16 |
3 files changed, 11 insertions, 9 deletions
diff --git a/crates/tor-checkable/Cargo.toml b/crates/tor-checkable/Cargo.toml index 6da1fd288..67c3cf1a3 100644 --- a/crates/tor-checkable/Cargo.toml +++ b/crates/tor-checkable/Cargo.toml @@ -22,6 +22,7 @@ humantime = "2" signature = "2" thiserror = "2" tor-llcrypto = { path = "../tor-llcrypto", version = "0.40.0" } +web-time-compat = { path = "../web-time-compat", version = "0.1.0" } [package.metadata.docs.rs] all-features = true [dev-dependencies] diff --git a/crates/tor-checkable/src/lib.rs b/crates/tor-checkable/src/lib.rs index 521ff4e70..3efc5dd8c 100644 --- a/crates/tor-checkable/src/lib.rs +++ b/crates/tor-checkable/src/lib.rs @@ -48,6 +48,7 @@ use std::time; use thiserror::Error; +use web_time_compat::{SystemTime, SystemTimeExt}; pub mod signed; pub mod timed; @@ -93,7 +94,7 @@ pub trait Timebound<T>: Sized { /// Unwrap this Timebound object if it is valid now. fn check_valid_now(self) -> Result<T, Self::Error> { - self.check_valid_at(&time::SystemTime::now()) + self.check_valid_at(&SystemTime::get()) } /// Unwrap this object if it is valid at the provided time t. diff --git a/crates/tor-checkable/src/timed.rs b/crates/tor-checkable/src/timed.rs index 72fd7dfb9..a187212e2 100644 --- a/crates/tor-checkable/src/timed.rs +++ b/crates/tor-checkable/src/timed.rs @@ -1,7 +1,7 @@ //! Convenience implementation of a TimeBound object. use std::ops::{Bound, Deref, RangeBounds}; -use std::time; +use web_time_compat as time; /// A TimeBound object that is valid for a specified range of time. /// @@ -9,10 +9,10 @@ use std::time; /// /// /// ``` -/// use std::time::{SystemTime, Duration}; +/// use web_time_compat::{SystemTime, SystemTimeExt, Duration}; /// use tor_checkable::{Timebound, TimeValidityError, timed::TimerangeBound}; /// -/// let now = SystemTime::now(); +/// let now = SystemTime::get(); /// let one_hour = Duration::new(3600, 0); /// /// // This seven is only valid for another hour! @@ -222,7 +222,7 @@ mod test { use super::*; use crate::{TimeValidityError, Timebound}; use humantime::parse_rfc3339; - use std::time::{Duration, SystemTime}; + use web_time_compat::{Duration, SystemTime, SystemTimeExt}; #[test] fn test_bounds() { @@ -309,7 +309,7 @@ mod test { assert_eq!(tr.check_valid_at_opt(None), Ok("hello world")); let tr = TimerangeBound::new("hello world", de..); assert_eq!( - tr.check_valid_at_opt(Some(SystemTime::now())), + tr.check_valid_at_opt(Some(SystemTime::get())), Ok("hello world") ); let tr = TimerangeBound::new("hello world", ..za); @@ -318,7 +318,7 @@ mod test { #[test] fn test_dangerous() { - let t1 = SystemTime::now(); + let t1 = SystemTime::get(); let t2 = t1 + Duration::from_secs(60 * 525600); let tr = TimerangeBound::new("cups of coffee", t1..=t2); @@ -332,7 +332,7 @@ mod test { #[test] fn test_map() { - let t1 = SystemTime::now(); + let t1 = SystemTime::get(); let min = Duration::from_secs(60); let tb = TimerangeBound::new(17_u32, t1..t1 + 5 * min); @@ -346,7 +346,7 @@ mod test { #[test] fn test_as_ref() { - let t1 = SystemTime::now(); + let t1 = SystemTime::get(); let min = Duration::from_secs(60); let tb1: TimerangeBound<String> = TimerangeBound::new("hi".into(), t1..t1 + 5 * min); |
