1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Time-source abstraction for testable time-dependent logic.
//!
//! [`TimeSource`] is a **sealed trait** — only crate-internal implementations are permitted.
//! This prevents external crates from accidentally introducing untestable time dependencies.
use OffsetDateTime;
/// An abstraction over time retrieval, enabling deterministic testing.
///
/// This trait is sealed — external crates cannot implement it.
/// A [`TimeSource`] that returns the real system time.
///
/// # Examples
///
/// ```
/// use security_core::time::{SystemTimeSource, TimeSource};
///
/// let ts = SystemTimeSource;
/// let now = ts.now();
/// // The returned time should be close to the true UTC time.
/// assert!(now.year() >= 2024);
/// ```
;
/// A [`TimeSource`] that always returns a fixed, pre-set time.
///
/// Use in tests to make time-dependent logic deterministic.
///
/// # Examples
///
/// ```
/// use security_core::time::{MockTimeSource, TimeSource};
/// use time::OffsetDateTime;
///
/// let fixed = OffsetDateTime::UNIX_EPOCH;
/// let ts = MockTimeSource::new(fixed);
/// assert_eq!(ts.now(), fixed);
/// ```