#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum Edition {
Fourth,
#[default]
Fifth,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Limits {
pub edition: Edition,
pub max_depth: usize,
pub max_attributes_per_element: usize,
pub max_attribute_size: usize,
pub max_name_length: usize,
pub max_nodes: Option<usize>,
pub max_text_length: Option<usize>,
pub max_xpath_depth: usize,
pub max_entity_depth: usize,
pub max_entity_expansion: usize,
pub max_xpath_operators: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
edition: Edition::Fifth,
max_depth: 256,
max_attributes_per_element: 1_000,
max_attribute_size: 524_288,
max_name_length: 1_000,
max_nodes: None,
max_text_length: None,
max_entity_depth: 10,
max_entity_expansion: 10_000_000,
max_xpath_depth: 256,
max_xpath_operators: 10_000,
}
}
}
impl Limits {
#[must_use]
pub fn permissive() -> Self {
Self {
edition: Edition::Fifth,
max_depth: Self::default().max_depth,
max_attributes_per_element: 100_000,
max_attribute_size: 64 * 1024 * 1024,
max_name_length: 1024 * 1024,
max_nodes: None,
max_text_length: None,
max_entity_depth: 40,
max_entity_expansion: 1_000_000_000,
max_xpath_depth: 1_000,
max_xpath_operators: 1_000_000,
}
}
#[must_use]
pub fn strict() -> Self {
Self {
edition: Edition::Fifth,
max_depth: 64,
max_attributes_per_element: 64,
max_attribute_size: 8 * 1024,
max_name_length: 256,
max_nodes: Some(100_000),
max_text_length: Some(1024 * 1024),
max_entity_depth: 4,
max_entity_expansion: 100_000,
max_xpath_depth: 32,
max_xpath_operators: 1_000,
}
}
}