synta 0.2.2

ASN.1 parser, decoder, and encoder library with DER/BER support and C FFI
Documentation
//! Decoder and encoder configuration

/// Configuration for the ASN.1 decoder.
///
/// Pass a `DecoderConfig` to the decoder to override the default resource
/// limits.  All limits are applied on a per-value basis during decoding and
/// are intended as a defence against malformed or malicious input.
#[derive(Debug, Clone)]
pub struct DecoderConfig {
    /// Maximum nesting depth for constructed types (default: 32).
    ///
    /// Each `SEQUENCE`, `SET`, or other constructed element entered via
    /// [`Decoder::enter_constructed`] increments the depth counter.  When the
    /// counter would exceed this limit, decoding returns
    /// [`Error::MaxDepthExceeded`].
    ///
    /// [`Decoder::enter_constructed`]: crate::Decoder::enter_constructed
    /// [`Error::MaxDepthExceeded`]: crate::Error::MaxDepthExceeded
    pub max_depth: usize,

    /// Maximum number of elements in a SEQUENCE OF or SET OF (default: 10 000).
    ///
    /// **Note:** this limit is currently enforced only in paths that explicitly
    /// count elements (e.g. `SequenceOf::count_elements`).  Eager `Sequence`
    /// and `Set` decode paths read until the content buffer is exhausted and
    /// do not apply this counter.  Do not rely on this field as a sole
    /// protection against deeply nested or extremely long sequences when using
    /// the eager constructed types.
    pub max_sequence_elements: usize,

    /// Maximum byte length of any single element's value (default: 16 MiB).
    ///
    /// When a length field exceeds this value, decoding returns
    /// [`Error::LengthExceedsMaximum`].
    ///
    /// [`Error::LengthExceedsMaximum`]: crate::Error::LengthExceedsMaximum
    pub max_length: usize,
}

impl Default for DecoderConfig {
    fn default() -> Self {
        Self {
            max_depth: 32,
            max_sequence_elements: 10_000,
            max_length: 16 * 1024 * 1024, // 16 MiB
        }
    }
}