use crate::error::Error;
use crate::parsing::source::Source;
pub const MAX_SPEC_NAME_LENGTH: usize = 128;
pub const MAX_FACT_NAME_LENGTH: usize = 256;
pub const MAX_RULE_NAME_LENGTH: usize = 256;
pub const MAX_TYPE_NAME_LENGTH: usize = 256;
pub const MAX_NUMBER_DIGITS: usize = 28;
pub const MAX_TEXT_VALUE_LENGTH: usize = 1024;
pub fn check_max_length(
name: &str,
limit: usize,
kind: &str,
source: Option<Source>,
) -> Result<(), Error> {
if name.len() > limit {
return Err(Error::resource_limit_exceeded(
format!("max_{kind}_name_length"),
format!("{limit} characters"),
format!("{} characters", name.len()),
format!("Shorten the {kind} name to at most {limit} characters"),
source,
None,
None,
));
}
Ok(())
}
#[derive(Debug, Clone)]
pub struct ResourceLimits {
pub max_file_size_bytes: usize,
pub max_expression_depth: usize,
pub max_expression_count: usize,
pub max_total_expression_count: usize,
pub max_fact_value_bytes: usize,
pub max_loaded_bytes: usize,
pub max_files: usize,
}
impl Default for ResourceLimits {
fn default() -> Self {
Self {
max_file_size_bytes: 5 * 1024 * 1024, max_expression_depth: 7,
max_expression_count: 4096,
max_total_expression_count: 3_141_592,
max_fact_value_bytes: 1024, max_loaded_bytes: 50 * 1024 * 1024, max_files: 4096,
}
}
}