Skip to main content

DecodeLimits

Struct DecodeLimits 

Source
pub struct DecodeLimits {
    pub max_input_bytes: usize,
    pub max_list_items: usize,
    pub max_nesting_depth: usize,
    pub max_total_allocation: usize,
    pub max_proof_nodes: usize,
    pub max_total_items: usize,
}
Expand description

Resource limits required by every untrusted decoder.

Fields§

§max_input_bytes: usize

Maximum accepted input length in bytes.

§max_list_items: usize

Maximum items accepted in any single decoded list.

§max_nesting_depth: usize

Maximum nested list depth.

§max_total_allocation: usize

Maximum total allocation a decoder may request.

§max_proof_nodes: usize

Maximum proof nodes accepted by a proof decoder.

§max_total_items: usize

Maximum total decoded items visited by one decoder invocation.

Implementations§

Source§

impl DecodeLimits

Source

pub const TEST_FIXTURE: Self

Limits for unit tests and conformance fixtures.

This is not a production policy. Production decoders should choose deployment-specific limits or start from Self::DEPLOYMENT_TEMPLATE.

Source

pub const DEPLOYMENT_TEMPLATE: Self

Deployment template for externally reachable wire decoders.

Using this constant unchanged in production is a security misconfiguration. Copy it, review every limit against the deployment’s concurrency and memory policy, and tighten values before release.

Source

pub fn check_input_len(self, len: usize) -> Result<(), DecodeError>

Validates the input length before parsing starts.

Source

pub fn check_list_count(self, count: usize) -> Result<(), DecodeError>

Validates a decoded list item count.

Source

pub fn check_nesting_depth(self, depth: usize) -> Result<(), DecodeError>

Validates the current nesting depth.

Source

pub fn check_single_allocation_limit( self, size: usize, ) -> Result<(), DecodeError>

Validates one requested allocation against the allocation budget.

This helper is for single-allocation checks only. Decoders that can make more than one allocation must use DecodeAccumulator to enforce the cumulative budget.

Source

pub fn check_proof_node_count(self, count: usize) -> Result<(), DecodeError>

Validates one proof-node count against the proof-node budget.

Decoders that traverse more than one proof segment must use DecodeAccumulator::account_proof_nodes for cumulative accounting.

Source

pub fn check_item_count(self, count: usize) -> Result<(), DecodeError>

Validates one decoded item count against the cumulative item budget.

This helper is for single-count checks only. Decoders that visit items incrementally must use DecodeAccumulator::account_items.

Source

pub const fn accumulator(self) -> DecodeAccumulator

Starts stateful budget accounting for a decoder invocation.

Trait Implementations§

Source§

impl Clone for DecodeLimits

Source§

fn clone(&self) -> DecodeLimits

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 DecodeLimits

Source§

impl Debug for DecodeLimits

Source§

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

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

impl Eq for DecodeLimits

Source§

impl PartialEq for DecodeLimits

Source§

fn eq(&self, other: &DecodeLimits) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DecodeLimits

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