Botan 3.13.0
Crypto and TLS for C&
Botan::ASN1_Pretty_Printer Class Referencefinal

#include <asn1_print.h>

Inheritance diagram for Botan::ASN1_Pretty_Printer:
Botan::ASN1_Formatter

Public Member Functions

 ASN1_Pretty_Printer (size_t print_limit=4096, size_t print_binary_limit=2048, bool print_context_specific=true, size_t initial_level=0, size_t value_column=60, size_t max_depth=64, bool require_der=false)
template<typename Alloc>
std::string print (const std::vector< uint8_t, Alloc > &vec) const
std::string print (const uint8_t in[], size_t len) const
void print_to_stream (std::ostream &out, const uint8_t in[], size_t len) const

Detailed Description

Format ASN.1 data into human readable output. The exact form of the output for any particular input is not guaranteed and may change from release to release.

Definition at line 100 of file asn1_print.h.

Constructor & Destructor Documentation

◆ ASN1_Pretty_Printer()

Botan::ASN1_Pretty_Printer::ASN1_Pretty_Printer ( size_t print_limit = 4096,
size_t print_binary_limit = 2048,
bool print_context_specific = true,
size_t initial_level = 0,
size_t value_column = 60,
size_t max_depth = 64,
bool require_der = false )
inlineexplicit

Create a pretty printer with the given settings

Parameters
print_limitstrings larger than this are not printed
print_binary_limitbinary strings larger than this are not printed
print_context_specificif true, try to parse nested context specific data.
initial_levelthe initial depth (0 or 1 are the only reasonable values)
value_columnASN.1 values are lined up at this column in output
max_depthdo not recurse more than this many times. If zero, recursion is unbounded.
require_derif true then non-canonical BER data is rejected

Definition at line 114 of file asn1_print.h.

120 :
121 ASN1_Formatter(print_context_specific, max_depth, require_der),
122 m_print_limit(print_limit),
123 m_print_binary_limit(print_binary_limit),
124 m_initial_level(initial_level),
125 m_value_column(value_column) {}
ASN1_Formatter(bool print_context_specific, size_t max_depth, bool require_der=false)
Definition asn1_print.h:35

References Botan::ASN1_Formatter::ASN1_Formatter().

Member Function Documentation

◆ print() [1/2]

template<typename Alloc>
std::string Botan::ASN1_Formatter::print ( const std::vector< uint8_t, Alloc > & vec) const
inlineinherited

Return the given ASN.1 data in formatted form

Parameters
vecthe DER or BER encoded data

Definition at line 61 of file asn1_print.h.

61 {
62 return print(vec.data(), vec.size());
63 }
std::string print(const uint8_t in[], size_t len) const

References print().

◆ print() [2/2]

std::string Botan::ASN1_Formatter::print ( const uint8_t in[],
size_t len ) const
inherited

Return the given ASN.1 data in formatted form

Parameters
inthe DER or BER encoded data
lenthe length of in in bytes

Definition at line 61 of file asn1_print.cpp.

61 {
62 std::ostringstream output;
63 print_to_stream(output, in, len);
64 return output.str();
65}
void print_to_stream(std::ostream &out, const uint8_t in[], size_t len) const

References print_to_stream().

Referenced by print().

◆ print_to_stream()

void Botan::ASN1_Formatter::print_to_stream ( std::ostream & out,
const uint8_t in[],
size_t len ) const
inherited

Format the given ASN.1 data, writing the result to a stream

Parameters
outthe stream to write the formatted output to
inthe DER or BER encoded data
lenthe length of in in bytes

Definition at line 67 of file asn1_print.cpp.

67 {
68 // The pretty printer is a best-effort diagnostic tool, so in BER mode it
69 // tolerates standalone EOC markers emitted by some BER producers.
70 const auto decoder_limits =
71 m_require_der ? BER_Decoder::Limits::DER() : BER_Decoder::Limits::BER().with_standalone_eoc_allowed();
72 BER_Decoder dec(std::span<const uint8_t>{in, len}, decoder_limits);
73 decode(output, dec, 0);
74}
static Limits DER()
Definition ber_dec.h:42

References Botan::BER_Decoder::Limits::BER(), Botan::BER_Decoder::Limits::DER(), and Botan::BER_Decoder::Limits::with_standalone_eoc_allowed().

Referenced by print().


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