| 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | use s2n_tls::callbacks::MonotonicClock; |
| 5 | use std::time::Duration; |
| 6 | use tokio::time::Instant; |
| 7 | |
| 8 | /// A monotonic clock that allows the s2n-tls C library time |
| 9 | /// to follow the tokio::time::pause behavior. |
| 10 | pub struct TokioTime(Instant); |
| 11 | |
| 12 | impl Default for TokioTime { |
| 13 | fn default() -> Self { |
| 14 | TokioTime(Instant::now()) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | impl MonotonicClock for TokioTime { |
| 19 | fn get_time(&self) -> Duration { |
| 20 | self.0.elapsed() |
| 21 | } |
| 22 | } |