pub struct DecodeLimits {
pub max_input_bytes: usize,
pub max_list_items: usize,
pub max_nesting_depth: usize,
pub max_total_allocation: usize,
}Expand description
Resource limits required by every untrusted decoder.
Fields§
§max_input_bytes: usizeMaximum accepted input length in bytes.
max_list_items: usizeMaximum items accepted in any decoded list.
max_nesting_depth: usizeMaximum nested list depth.
max_total_allocation: usizeMaximum total allocation a decoder may request.
Implementations§
Source§impl DecodeLimits
impl DecodeLimits
Sourcepub const TEST_FIXTURE: Self
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::PRODUCTION_RECOMMENDED.
Sourcepub const PRODUCTION_RECOMMENDED: Self
pub const PRODUCTION_RECOMMENDED: Self
Recommended starting point for production wire decoders.
Review and tighten these values per deployment context before relying on them for externally reachable services.
Sourcepub fn check_input_len(self, len: usize) -> Result<(), DecodeError>
pub fn check_input_len(self, len: usize) -> Result<(), DecodeError>
Validates the input length before parsing starts.
Sourcepub fn check_list_count(self, count: usize) -> Result<(), DecodeError>
pub fn check_list_count(self, count: usize) -> Result<(), DecodeError>
Validates a decoded list item count.
Sourcepub fn check_nesting_depth(self, depth: usize) -> Result<(), DecodeError>
pub fn check_nesting_depth(self, depth: usize) -> Result<(), DecodeError>
Validates the current nesting depth.
Sourcepub fn check_single_allocation_limit(
self,
size: usize,
) -> Result<(), DecodeError>
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.
Sourcepub const fn accumulator(self) -> DecodeAccumulator
pub const fn accumulator(self) -> DecodeAccumulator
Starts stateful budget accounting for a decoder invocation.
Trait Implementations§
Source§impl Clone for DecodeLimits
impl Clone for DecodeLimits
Source§fn clone(&self) -> DecodeLimits
fn clone(&self) -> DecodeLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for DecodeLimits
Source§impl Debug for DecodeLimits
impl Debug for DecodeLimits
impl Eq for DecodeLimits
Source§impl PartialEq for DecodeLimits
impl PartialEq for DecodeLimits
Source§fn eq(&self, other: &DecodeLimits) -> bool
fn eq(&self, other: &DecodeLimits) -> bool
self and other values to be equal, and is used by ==.