use crate::capability::CapabilitySet;
use crate::error::Result;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::{extension_consume, extension_issue_file, extension_release};
#[cfg(target_os = "linux")]
pub use linux::{
classify_access_from_flags, deny_notif, inject_fd, install_seccomp_notify, notif_id_valid,
read_notif_path, read_open_how, recv_notif, validate_openat2_size, OpenHow, SeccompData,
SeccompNotif, SYS_OPENAT, SYS_OPENAT2,
};
#[derive(Debug, Clone)]
pub struct SupportInfo {
pub is_supported: bool,
pub platform: &'static str,
pub details: String,
}
pub struct Sandbox;
impl Sandbox {
#[must_use = "sandbox application result should be checked"]
pub fn apply(caps: &CapabilitySet) -> Result<()> {
#[cfg(target_os = "linux")]
{
linux::apply(caps)
}
#[cfg(target_os = "macos")]
{
macos::apply(caps)
}
#[cfg(target_arch = "wasm32")]
{
Err(crate::error::NonoError::UnsupportedPlatform(
"WASM: Browser sandboxing requires different approach (CSP, iframe sandbox)".into(),
))
}
#[cfg(not(any(target_os = "linux", target_os = "macos", target_arch = "wasm32")))]
{
Err(crate::error::NonoError::UnsupportedPlatform(
std::env::consts::OS.to_string(),
))
}
}
#[must_use]
pub fn is_supported() -> bool {
#[cfg(target_os = "linux")]
{
linux::is_supported()
}
#[cfg(target_os = "macos")]
{
macos::is_supported()
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
false
}
}
#[must_use]
pub fn support_info() -> SupportInfo {
#[cfg(target_os = "linux")]
{
linux::support_info()
}
#[cfg(target_os = "macos")]
{
macos::support_info()
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
SupportInfo {
is_supported: false,
platform: std::env::consts::OS,
details: format!("Platform '{}' is not supported", std::env::consts::OS),
}
}
}
}