use std::collections::HashMap;
use super::super::governed::GovernedString;
const UNCONDITIONAL_KEYS: [&str; 2] = ["thoughtSignature", "thought_signature"];
const TYPED_KEYS: [(&str, &str); 3] = [
("signature", "thinking"),
("data", "redacted_thinking"),
("encrypted_content", "reasoning"),
];
const TYPE_KEY: &str = "type";
#[derive(Debug, Default)]
pub struct SignatureExemptions {
types: HashMap<String, String>,
}
impl SignatureExemptions {
#[must_use]
pub fn from_strings(strings: &[GovernedString<'_>]) -> Self {
let mut types = HashMap::new();
for found in strings {
if let Some((parent, key)) = split_path(&found.path)
&& key == TYPE_KEY
{
types.insert(parent.to_owned(), found.value.to_owned());
}
}
Self { types }
}
#[must_use]
pub fn exempts_entropy(&self, path: &str) -> bool {
let Some((parent, key)) = split_path(path) else {
return false;
};
if UNCONDITIONAL_KEYS.contains(&key) {
return true;
}
TYPED_KEYS.iter().any(|&(name, block_type)| {
key == name && self.types.get(parent).is_some_and(|t| t == block_type)
})
}
}
fn split_path(path: &str) -> Option<(&str, &str)> {
let (parent, key) = path.rsplit_once('.')?;
(!key.is_empty() && !key.contains('[')).then_some((parent, key))
}