pub struct DeserializerConfig { /* private fields */ }Expand description
Configuration for CBOR deserializer to prevent DoS attacks.
This struct provides configurable limits for deserialization to protect against malicious inputs that could consume excessive memory or CPU resources.
§Examples
use multi_cbor::config::DeserializerConfig;
let config = DeserializerConfig::default()
.max_array_size(1000)
.max_map_size(500)
.max_recursion_depth(64);Implementations§
Source§impl DeserializerConfig
impl DeserializerConfig
Sourcepub const fn unlimited() -> Self
pub const fn unlimited() -> Self
Creates a new configuration with no limits (use with caution).
This is potentially dangerous as it allows unbounded resource consumption. Only use this when you have full control over the input data.
Sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Creates a strict configuration with conservative limits for untrusted input.
Strict limits:
- Max array size: 1,000 elements
- Max map size: 1,000 key-value pairs
- Max recursion depth: 32 levels
- Max indefinite iterations: 1,000
Sourcepub const fn max_array_size(self, limit: usize) -> Self
pub const fn max_array_size(self, limit: usize) -> Self
Sets the maximum number of elements allowed in an array.
Pass None to disable this limit (not recommended for untrusted input).
Sourcepub const fn unlimited_array_size(self) -> Self
pub const fn unlimited_array_size(self) -> Self
Removes the limit on array size (use with caution).
Sourcepub const fn max_map_size(self, limit: usize) -> Self
pub const fn max_map_size(self, limit: usize) -> Self
Sets the maximum number of key-value pairs allowed in a map.
Pass None to disable this limit (not recommended for untrusted input).
Sourcepub const fn unlimited_map_size(self) -> Self
pub const fn unlimited_map_size(self) -> Self
Removes the limit on map size (use with caution).
Sourcepub const fn max_recursion_depth(self, depth: u8) -> Self
pub const fn max_recursion_depth(self, depth: u8) -> Self
Sets the maximum recursion depth for nested structures.
Lower values provide better DoS protection but may reject legitimate deeply nested data.
Sourcepub const fn max_indefinite_iterations(self, limit: usize) -> Self
pub const fn max_indefinite_iterations(self, limit: usize) -> Self
Sets the maximum number of iterations for indefinite-length structures.
This prevents attackers from sending indefinite-length arrays or maps with extremely large numbers of elements.
Sourcepub const fn unlimited_indefinite_iterations(self) -> Self
pub const fn unlimited_indefinite_iterations(self) -> Self
Removes the limit on indefinite-length iterations (use with caution).
Sourcepub const fn get_max_array_size(&self) -> Option<usize>
pub const fn get_max_array_size(&self) -> Option<usize>
Returns the maximum array size limit.
Sourcepub const fn get_max_map_size(&self) -> Option<usize>
pub const fn get_max_map_size(&self) -> Option<usize>
Returns the maximum map size limit.
Sourcepub const fn get_max_recursion_depth(&self) -> u8
pub const fn get_max_recursion_depth(&self) -> u8
Returns the maximum recursion depth.
Sourcepub const fn get_max_indefinite_iterations(&self) -> Option<usize>
pub const fn get_max_indefinite_iterations(&self) -> Option<usize>
Returns the maximum indefinite iterations limit.
Trait Implementations§
Source§impl Clone for DeserializerConfig
impl Clone for DeserializerConfig
Source§fn clone(&self) -> DeserializerConfig
fn clone(&self) -> DeserializerConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more