Botan 3.13.0
Crypto and TLS for C&
Botan::BER_Decoder::Limits Class Referencefinal

#include <ber_dec.h>

Public Member Functions

bool allow_ber_encoding () const
bool allow_standalone_eoc () const
size_t max_nested_indefinite_length () const
std::optional< size_t > max_object_size () const
bool operator== (const Limits &) const =default
bool reject_default_value_encoding () const
bool require_der_encoding () const
Limits with_default_value_encoding_rejected () const
Limits with_max_object_size (std::optional< size_t > max_object_size) const
Limits with_standalone_eoc_allowed () const

Static Public Member Functions

static Limits BER (size_t max_nested_indef=16)
static Limits DER ()

Static Public Attributes

static constexpr size_t DefaultMaxObjectSize = 128 * 1024 * 1024

Detailed Description

Controls what encoding rules the decoder accepts.

Definition at line 32 of file ber_dec.h.

Member Function Documentation

◆ allow_ber_encoding()

bool Botan::BER_Decoder::Limits::allow_ber_encoding ( ) const
inline

If true, non-canonical BER encodings are accepted

Definition at line 56 of file ber_dec.h.

56{ return m_allow_ber; }

Referenced by require_der_encoding().

◆ allow_standalone_eoc()

bool Botan::BER_Decoder::Limits::allow_standalone_eoc ( ) const
inline

If true, a standalone EOC marker (one that does not terminate an indefinite-length encoding) is skipped rather than rejected. Some BER producers emit trailing EOC markers; accepting them is needed to parse such data (eg CMS signatures in PDFs). Off by default.

Definition at line 74 of file ber_dec.h.

74{ return m_allow_standalone_eoc; }

Referenced by operator==().

◆ BER()

Limits Botan::BER_Decoder::Limits::BER ( size_t max_nested_indef = 16)
inlinestatic

Accept non-canonical BER encodings.

Parameters
max_nested_indefmaximum number of nested indefinite-length encodings accepted

Definition at line 49 of file ber_dec.h.

49 {
50 return Limits(true, max_nested_indef, false, DefaultMaxObjectSize, false);
51 }
static constexpr size_t DefaultMaxObjectSize
Definition ber_dec.h:37

References DefaultMaxObjectSize.

Referenced by Botan::BER_Decoder::BER_Decoder(), and Botan::ASN1_Formatter::print_to_stream().

◆ DER()

◆ max_nested_indefinite_length()

size_t Botan::BER_Decoder::Limits::max_nested_indefinite_length ( ) const
inline

The maximum number of nested indefinite-length encodings accepted

Definition at line 66 of file ber_dec.h.

66{ return m_max_nested_indef; }

◆ max_object_size()

std::optional< size_t > Botan::BER_Decoder::Limits::max_object_size ( ) const
inline

The maximum size in bytes of a single decoded object, or nullopt if no object size limit is enforced.

Definition at line 80 of file ber_dec.h.

80{ return m_max_object_size; }

Referenced by operator==(), and with_max_object_size().

◆ operator==()

bool Botan::BER_Decoder::Limits::operator== ( const Limits & ) const
default

Compare two sets of limits for equality

References allow_standalone_eoc(), max_object_size(), and reject_default_value_encoding().

◆ reject_default_value_encoding()

bool Botan::BER_Decoder::Limits::reject_default_value_encoding ( ) const
inline

If true, a DER component that is explicitly encoded with a value equal to its DEFAULT is rejected (such components must be omitted in DER). Only applies in DER mode and only to fields decoded via decode_default(). Off by default, since Botan and many other implementations emit such components. See decode_default().

Definition at line 89 of file ber_dec.h.

89{ return m_reject_default_value_encoding; }

Referenced by operator==().

◆ require_der_encoding()

bool Botan::BER_Decoder::Limits::require_der_encoding ( ) const
inline

If true, only DER encodings are accepted

Definition at line 61 of file ber_dec.h.

61{ return !allow_ber_encoding(); }
bool allow_ber_encoding() const
Definition ber_dec.h:56

References allow_ber_encoding().

◆ with_default_value_encoding_rejected()

Limits Botan::BER_Decoder::Limits::with_default_value_encoding_rejected ( ) const
inline

Return a copy of these limits that rejects DER components encoded equal to their DEFAULT value. See reject_default_value_encoding().

Definition at line 116 of file ber_dec.h.

116 {
117 Limits copy = *this;
118 copy.m_reject_default_value_encoding = true;
119 return copy;
120 }

◆ with_max_object_size()

Limits Botan::BER_Decoder::Limits::with_max_object_size ( std::optional< size_t > max_object_size) const
inline

Return a copy of these limits with the given maximum object size. A value of nullopt disables the object size limit. See max_object_size().

Definition at line 106 of file ber_dec.h.

106 {
107 Limits copy = *this;
108 copy.m_max_object_size = max_object_size;
109 return copy;
110 }
std::optional< size_t > max_object_size() const
Definition ber_dec.h:80

References max_object_size().

◆ with_standalone_eoc_allowed()

Limits Botan::BER_Decoder::Limits::with_standalone_eoc_allowed ( ) const
inline

Return a copy of these limits that tolerates standalone EOC markers. See allow_standalone_eoc().

Definition at line 95 of file ber_dec.h.

95 {
96 Limits copy = *this;
97 copy.m_allow_standalone_eoc = true;
98 return copy;
99 }

Referenced by Botan::ASN1_Formatter::print_to_stream().

Member Data Documentation

◆ DefaultMaxObjectSize

size_t Botan::BER_Decoder::Limits::DefaultMaxObjectSize = 128 * 1024 * 1024
staticconstexpr

The default maximum size in bytes of a single decoded object.

Definition at line 37 of file ber_dec.h.

Referenced by BER(), and DER().


The documentation for this class was generated from the following file: