Skip to main content

DeserializerConfig

Struct DeserializerConfig 

Source
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

Source

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.

Source

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
Source

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).

Source

pub const fn unlimited_array_size(self) -> Self

Removes the limit on array size (use with caution).

Source

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).

Source

pub const fn unlimited_map_size(self) -> Self

Removes the limit on map size (use with caution).

Source

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.

Source

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.

Source

pub const fn unlimited_indefinite_iterations(self) -> Self

Removes the limit on indefinite-length iterations (use with caution).

Source

pub const fn get_max_array_size(&self) -> Option<usize>

Returns the maximum array size limit.

Source

pub const fn get_max_map_size(&self) -> Option<usize>

Returns the maximum map size limit.

Source

pub const fn get_max_recursion_depth(&self) -> u8

Returns the maximum recursion depth.

Source

pub const fn get_max_indefinite_iterations(&self) -> Option<usize>

Returns the maximum indefinite iterations limit.

Trait Implementations§

Source§

impl Clone for DeserializerConfig

Source§

fn clone(&self) -> DeserializerConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DeserializerConfig

Source§

impl Debug for DeserializerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DeserializerConfig

Source§

fn default() -> Self

Creates a default configuration with reasonable limits.

Default limits:

  • Max array size: 100,000 elements
  • Max map size: 100,000 key-value pairs
  • Max recursion depth: 128 levels
  • Max indefinite iterations: 100,000

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.