Skip to main content

validate_config_entry

Function validate_config_entry 

Source
pub fn validate_config_entry(value: &str, field: &str) -> Result<()>
Expand description

Validates a single caller-supplied SecurityConfig entry string. Shared by exarch-python and exarch-node. Validates a single caller-supplied SecurityConfig entry string.

This is the shared boundary check for exarch-python and exarch-node entry points that build allowed_extensions and banned_path_components (add_allowed_extension, add_banned_component, and their with_* equivalents), and is also called per-entry from crate::config::SecurityConfig::validate as the backstop every entry point funnels through. field names the caller’s field for the error message (e.g. "extension", "banned path component").

§Check order

  1. Length, checked before scanning for a null byte, for the same O(1)-before-O(n) reason as validate_raw_path_str.
  2. Null byte.
  3. Emptiness — unlike validate_raw_path_str, which accepts "", an empty entry is rejected here: in banned_path_components it is inert, and in allowed_extensions it silently flips the config from “allow all” to an allowlist that matches nothing.

§Errors

Returns ArchiveError::InvalidConfiguration if value exceeds MAX_CONFIG_ENTRY_LENGTH bytes, contains a null byte, or is empty.

§Examples

use exarch_core::validate_config_entry;

assert!(validate_config_entry("txt", "extension").is_ok());
assert!(validate_config_entry("", "extension").is_err());
assert!(validate_config_entry("bad\0ext", "extension").is_err());
assert!(validate_config_entry(&"x".repeat(256), "extension").is_err());