use std::collections::HashSet;
#[derive(Debug, Clone, Default)]
pub struct NetworkSecurity {
pub trusted_domains: HashSet<String>,
}
impl NetworkSecurity {
pub fn new() -> Self {
Self {
trusted_domains: HashSet::new(),
}
}
pub fn is_domain_allowed(&self, domain: &str) -> bool {
self.trusted_domains.is_empty() || self.trusted_domains.contains(domain)
}
#[allow(dead_code)]
pub fn add_domain(&mut self, domain: &str) {
self.trusted_domains.insert(domain.to_string());
}
#[allow(dead_code)]
pub fn remove_domain(&mut self, domain: &str) {
self.trusted_domains.remove(domain);
}
#[allow(dead_code)]
pub fn set_domains(&mut self, domains: &[String]) {
self.trusted_domains.clear();
for domain in domains {
self.trusted_domains.insert(domain.clone());
}
}
#[allow(dead_code)]
pub fn get_domains(&self) -> Vec<String> {
self.trusted_domains.iter().cloned().collect()
}
#[allow(dead_code)]
pub fn clear_domains(&mut self) {
self.trusted_domains.clear();
}
}