use std::collections::BTreeSet;
use super::default_sensitive_names::{
canonicalize_structured_sensitive_name,
DEFAULT_SENSITIVE_QUERY_PARAM_NAMES,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SensitiveQueryParams {
names: BTreeSet<String>,
}
impl SensitiveQueryParams {
pub fn new() -> Self {
Self {
names: BTreeSet::new(),
}
}
pub fn contains(&self, name: &str) -> bool {
self.names
.contains(&canonicalize_structured_sensitive_name(name))
}
pub fn insert(&mut self, name: &str) {
let value = canonicalize_structured_sensitive_name(name);
if !value.is_empty() {
self.names.insert(value);
}
}
pub fn extend<I, S>(&mut self, names: I)
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
for name in names {
self.insert(name.as_ref());
}
}
pub fn clear(&mut self) {
self.names.clear();
}
pub fn len(&self) -> usize {
self.names.len()
}
pub fn is_empty(&self) -> bool {
self.names.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = &str> {
self.names.iter().map(String::as_str)
}
}
impl Default for SensitiveQueryParams {
fn default() -> Self {
let mut result = Self::new();
result.extend(DEFAULT_SENSITIVE_QUERY_PARAM_NAMES);
result
}
}