#[derive(Debug, Clone)]
pub struct SecurityConfig {
pub protect_user_home: bool,
pub allow_tcc_prompts: bool,
pub protect_credentials: bool,
pub protect_cloud_config: bool,
pub protect_browser_data: bool,
pub protect_keychain: bool,
pub protect_shell_history: bool,
pub protect_package_credentials: bool,
pub allow_gpu: bool,
pub allow_npu: bool,
pub allow_hardware: bool,
}
impl Default for SecurityConfig {
fn default() -> Self {
Self::strict()
}
}
impl SecurityConfig {
pub fn strict() -> Self {
Self {
protect_user_home: true,
allow_tcc_prompts: false,
protect_credentials: true,
protect_cloud_config: true,
protect_browser_data: true,
protect_keychain: true,
protect_shell_history: true,
protect_package_credentials: true,
allow_gpu: true,
allow_npu: true,
allow_hardware: false,
}
}
pub fn permissive() -> Self {
Self {
protect_user_home: false,
allow_tcc_prompts: true,
protect_credentials: false,
protect_cloud_config: false,
protect_browser_data: false,
protect_keychain: false,
protect_shell_history: false,
protect_package_credentials: false,
allow_gpu: true,
allow_npu: true,
allow_hardware: true,
}
}
pub fn interactive() -> Self {
Self {
protect_user_home: true,
allow_tcc_prompts: true,
protect_credentials: true,
protect_cloud_config: true,
protect_browser_data: true,
protect_keychain: true,
protect_shell_history: true,
protect_package_credentials: true,
allow_gpu: true,
allow_npu: true,
allow_hardware: false,
}
}
pub fn builder() -> SecurityConfigBuilder {
SecurityConfigBuilder::default()
}
}
#[derive(Debug, Clone, Default)]
pub struct SecurityConfigBuilder {
config: SecurityConfig,
}
impl SecurityConfigBuilder {
pub fn from_permissive() -> Self {
Self {
config: SecurityConfig::permissive(),
}
}
pub fn protect_user_home(mut self, enabled: bool) -> Self {
self.config.protect_user_home = enabled;
self
}
pub fn allow_tcc_prompts(mut self, enabled: bool) -> Self {
self.config.allow_tcc_prompts = enabled;
self
}
pub fn protect_credentials(mut self, enabled: bool) -> Self {
self.config.protect_credentials = enabled;
self
}
pub fn protect_cloud_config(mut self, enabled: bool) -> Self {
self.config.protect_cloud_config = enabled;
self
}
pub fn protect_browser_data(mut self, enabled: bool) -> Self {
self.config.protect_browser_data = enabled;
self
}
pub fn protect_keychain(mut self, enabled: bool) -> Self {
self.config.protect_keychain = enabled;
self
}
pub fn protect_shell_history(mut self, enabled: bool) -> Self {
self.config.protect_shell_history = enabled;
self
}
pub fn protect_package_credentials(mut self, enabled: bool) -> Self {
self.config.protect_package_credentials = enabled;
self
}
pub fn allow_gpu(mut self, enabled: bool) -> Self {
self.config.allow_gpu = enabled;
self
}
pub fn allow_npu(mut self, enabled: bool) -> Self {
self.config.allow_npu = enabled;
self
}
pub fn allow_hardware(mut self, enabled: bool) -> Self {
self.config.allow_hardware = enabled;
self
}
pub fn build(self) -> SecurityConfig {
self.config
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_strict_has_all_protections() {
let config = SecurityConfig::strict();
assert!(config.protect_user_home);
assert!(!config.allow_tcc_prompts); assert!(config.protect_credentials);
assert!(config.protect_cloud_config);
assert!(config.protect_browser_data);
assert!(config.protect_keychain);
assert!(config.protect_shell_history);
assert!(config.protect_package_credentials);
assert!(config.allow_gpu);
assert!(config.allow_npu);
assert!(!config.allow_hardware);
}
#[test]
fn test_permissive_has_no_protections() {
let config = SecurityConfig::permissive();
assert!(!config.protect_user_home);
assert!(config.allow_tcc_prompts); assert!(!config.protect_credentials);
assert!(!config.protect_cloud_config);
assert!(!config.protect_browser_data);
assert!(!config.protect_keychain);
assert!(!config.protect_shell_history);
assert!(!config.protect_package_credentials);
assert!(config.allow_gpu);
assert!(config.allow_npu);
assert!(config.allow_hardware);
}
#[test]
fn test_interactive_allows_tcc_prompts() {
let config = SecurityConfig::interactive();
assert!(config.protect_user_home);
assert!(config.allow_tcc_prompts); assert!(config.protect_credentials);
assert!(config.protect_cloud_config);
assert!(config.protect_browser_data);
assert!(config.protect_keychain);
assert!(config.protect_shell_history);
assert!(config.protect_package_credentials);
assert!(config.allow_gpu);
assert!(config.allow_npu);
assert!(!config.allow_hardware);
}
#[test]
fn test_builder_custom() {
let config = SecurityConfig::builder()
.protect_user_home(false)
.protect_credentials(true)
.protect_browser_data(false)
.build();
assert!(!config.protect_user_home);
assert!(config.protect_credentials);
assert!(!config.protect_browser_data);
}
#[test]
fn test_builder_from_permissive() {
let config = SecurityConfigBuilder::from_permissive()
.protect_credentials(true)
.build();
assert!(config.protect_credentials);
assert!(!config.protect_user_home);
assert!(!config.protect_browser_data);
}
}