pub struct EvaluationConfig {
pub max_recursion_depth: u32,
pub max_string_length: usize,
pub stop_at_first_match: bool,
pub enable_mime_types: bool,
pub timeout_ms: Option<u64>,
}Expand description
Configuration for rule evaluation
This struct controls various aspects of magic rule evaluation behavior, including performance limits, output options, and matching strategies.
§Examples
use libmagic_rs::EvaluationConfig;
// Use default configuration
let config = EvaluationConfig::default();
// Create custom configuration
let custom_config = EvaluationConfig {
max_recursion_depth: 10,
max_string_length: 4096,
stop_at_first_match: false, // Get all matches
enable_mime_types: true,
timeout_ms: Some(5000), // 5 second timeout
};Fields§
§max_recursion_depth: u32Maximum recursion depth for nested rules
This prevents infinite recursion in malformed magic files and limits the depth of rule hierarchy traversal. Default is 20.
max_string_length: usizeMaximum string length to read
This limits the amount of data read for string types to prevent excessive memory usage. Default is 8192 bytes.
stop_at_first_match: boolStop at first match or continue for all matches
When true, evaluation stops after the first matching rule.
When false, all rules are evaluated to find all matches.
Default is true for performance.
enable_mime_types: boolEnable MIME type mapping in results
When true, the evaluator will attempt to map file type descriptions
to standard MIME types. Default is false.
timeout_ms: Option<u64>Timeout for evaluation in milliseconds
If set, evaluation will be aborted if it takes longer than this duration.
None means no timeout. Default is None.
Implementations§
Source§impl EvaluationConfig
impl EvaluationConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new configuration with default values
§Examples
use libmagic_rs::EvaluationConfig;
let config = EvaluationConfig::new();
assert_eq!(config.max_recursion_depth, 20);
assert_eq!(config.max_string_length, 8192);
assert!(config.stop_at_first_match);
assert!(!config.enable_mime_types);
assert_eq!(config.timeout_ms, None);Sourcepub const fn performance() -> Self
pub const fn performance() -> Self
Create a configuration optimized for performance
This configuration prioritizes speed over completeness:
- Lower recursion depth limit
- Smaller string length limit
- Stop at first match
- No MIME type mapping
- Short timeout
§Examples
use libmagic_rs::EvaluationConfig;
let config = EvaluationConfig::performance();
assert_eq!(config.max_recursion_depth, 10);
assert_eq!(config.max_string_length, 1024);
assert!(config.stop_at_first_match);
assert!(!config.enable_mime_types);
assert_eq!(config.timeout_ms, Some(1000));Sourcepub const fn comprehensive() -> Self
pub const fn comprehensive() -> Self
Create a configuration optimized for completeness
This configuration prioritizes finding all matches over speed:
- Higher recursion depth limit
- Larger string length limit
- Find all matches
- Enable MIME type mapping
- Longer timeout
§Examples
use libmagic_rs::EvaluationConfig;
let config = EvaluationConfig::comprehensive();
assert_eq!(config.max_recursion_depth, 50);
assert_eq!(config.max_string_length, 32768);
assert!(!config.stop_at_first_match);
assert!(config.enable_mime_types);
assert_eq!(config.timeout_ms, Some(30000));Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the configuration settings
Performs comprehensive security validation of all configuration values to prevent malicious configurations that could lead to resource exhaustion, denial of service, or other security issues.
§Security
This validation prevents:
- Stack overflow attacks through excessive recursion depth
- Memory exhaustion through oversized string limits
- Denial of service through excessive timeouts
- Integer overflow in configuration calculations
§Errors
Returns LibmagicError::InvalidFormat if any configuration values
are invalid or out of reasonable bounds.
§Examples
use libmagic_rs::EvaluationConfig;
let config = EvaluationConfig::default();
assert!(config.validate().is_ok());
let invalid_config = EvaluationConfig {
max_recursion_depth: 0, // Invalid: must be > 0
..Default::default()
};
assert!(invalid_config.validate().is_err());Trait Implementations§
Source§impl Clone for EvaluationConfig
impl Clone for EvaluationConfig
Source§fn clone(&self) -> EvaluationConfig
fn clone(&self) -> EvaluationConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more