1 | //! The library's source of time. |
2 | |
3 | use core::fmt::Debug; |
4 | |
5 | use pki_types::UnixTime; |
6 | |
7 | /// An object that provides the current time. |
8 | /// |
9 | /// This is used to, for example, check if a certificate has expired during |
10 | /// certificate validation, or to check the age of a ticket. |
11 | pub trait TimeProvider: Debug + Send + Sync { |
12 | /// Returns the current wall time. |
13 | /// |
14 | /// This is not required to be monotonic. |
15 | /// |
16 | /// Return `None` if unable to retrieve the time. |
17 | fn current_time(&self) -> Option<UnixTime>; |
18 | } |
19 | |
20 | #[derive (Debug)] |
21 | #[cfg (feature = "std" )] |
22 | /// Default `TimeProvider` implementation that uses `std` |
23 | pub struct DefaultTimeProvider; |
24 | |
25 | #[cfg (feature = "std" )] |
26 | impl TimeProvider for DefaultTimeProvider { |
27 | fn current_time(&self) -> Option<UnixTime> { |
28 | Some(UnixTime::now()) |
29 | } |
30 | } |
31 | |