1#![cfg_attr(not(feature = "std"), no_std)]
7#![forbid(unsafe_code)]
8
9#[cfg(not(feature = "std"))]
12extern crate alloc;
13
14pub mod entropy;
15pub mod time;
16
17#[cfg(feature = "rand-core")]
18pub use entropy::RandCoreEntropy;
19#[cfg(feature = "std")]
20pub use entropy::StdEntropy;
21pub use entropy::{EntropySource, TestEntropySource};
22#[cfg(feature = "std")]
23pub use time::StdTimeSource;
24pub use time::{noxtls_format_unix_secs_as_generalized_time, StaticTimeSource, TimeSource};
25
26pub type MonotonicMillis = u64;
28
29#[cfg(feature = "std")]
31pub type GeneralizedTimeString = std::string::String;
32#[cfg(all(feature = "alloc", not(feature = "std")))]
33pub type GeneralizedTimeString = alloc::string::String;
34#[cfg(not(any(feature = "std", feature = "alloc")))]
35#[derive(Clone, Copy, Debug, Eq, PartialEq)]
36pub struct GeneralizedTimeString([u8; 15]);
37
38#[cfg(not(any(feature = "std", feature = "alloc")))]
39impl GeneralizedTimeString {
40 #[must_use]
41 pub(crate) fn from_bytes(bytes: [u8; 15]) -> Self {
42 Self(bytes)
43 }
44
45 #[must_use]
46 pub fn as_str(&self) -> &str {
47 core::str::from_utf8(&self.0).expect("GeneralizedTimeString contains only ASCII digits")
48 }
49}
50
51#[cfg(not(any(feature = "std", feature = "alloc")))]
52impl AsRef<str> for GeneralizedTimeString {
53 fn as_ref(&self) -> &str {
54 self.as_str()
55 }
56}
57
58#[cfg(not(any(feature = "std", feature = "alloc")))]
59impl core::fmt::Display for GeneralizedTimeString {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 f.write_str(self.as_str())
62 }
63}
64
65#[cfg(feature = "std")]
67#[must_use]
68pub fn noxtls_unix_timestamp_secs() -> u64 {
69 use std::time::{SystemTime, UNIX_EPOCH};
70 SystemTime::now()
71 .duration_since(UNIX_EPOCH)
72 .map_or(0, |d| d.as_secs())
73}