use std::time::{SystemTime, UNIX_EPOCH};
pub mod console;
pub mod entropy;
pub mod ipc;
pub mod openat;
pub mod paths;
pub mod privatefs;
pub mod process;
pub mod sealed;
pub use console::{ActiveConsoleControl, ConsoleControl, HandlerContract};
pub use entropy::{ActiveEntropy, Entropy};
pub use ipc::{ActiveIpc, Ipc, IpcListener, Liveness, PeerReject};
pub use openat::{ActiveDirHandle, DirHandle, Excl, GuardIo, NodeId, NodeKind, OpenMode};
pub use paths::{ActiveKnownPaths, KnownPaths};
pub use privatefs::{ActivePrivateFs, EffectiveAccess, PrivateFs, Writes};
pub use process::{ActiveProcessControl, ProcessControl, TreeReaper};
pub const PRIVATE_FS: ActivePrivateFs = ActivePrivateFs::new();
pub const KNOWN_PATHS: ActiveKnownPaths = ActiveKnownPaths::new();
pub const ENTROPY: ActiveEntropy = ActiveEntropy::new();
pub const PROCESS_CONTROL: ActiveProcessControl = ActiveProcessControl::new();
pub const IPC: ActiveIpc = ActiveIpc::new();
pub const CONSOLE: ActiveConsoleControl = ActiveConsoleControl::new();
#[cfg(test)]
pub(crate) static ENV_GUARD: std::sync::Mutex<()> = std::sync::Mutex::new(());
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Unsupported {
pub capability: &'static str,
pub platform: &'static str,
pub because: &'static str,
}
impl Unsupported {
pub const fn new(capability: &'static str, because: &'static str) -> Self {
Self {
capability,
platform: std::env::consts::OS,
because,
}
}
}
impl std::fmt::Display for Unsupported {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} is not available on {}: {}",
self.capability, self.platform, self.because
)
}
}
impl std::error::Error for Unsupported {}
impl From<Unsupported> for std::io::Error {
fn from(u: Unsupported) -> Self {
std::io::Error::new(std::io::ErrorKind::Unsupported, u.to_string())
}
}
pub trait Clock: Send + Sync {
fn now_ms(&self) -> u64;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct SystemClock;
impl Clock for SystemClock {
fn now_ms(&self) -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_millis() as u64)
.unwrap_or(0)
}
}
pub trait SecretStore: Send + Sync {
fn get(&self, name: &str) -> Option<String>;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct EnvSecrets;
impl SecretStore for EnvSecrets {
fn get(&self, name: &str) -> Option<String> {
std::env::var(name).ok().filter(|v| !v.is_empty())
}
}