Botan 3.13.0
Crypto and TLS for C&
Botan::ASN1_Formatter Class Referenceabstract

#include <asn1_print.h>

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

Public Member Functions

 ASN1_Formatter (bool print_context_specific, size_t max_depth, 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
virtual ~ASN1_Formatter ()=default

Protected Member Functions

virtual std::string format (ASN1_Type type_tag, ASN1_Class class_tag, size_t level, size_t length, std::string_view value) const =0
virtual std::string format_bin (ASN1_Type type_tag, ASN1_Class class_tag, const std::vector< uint8_t > &vec) const =0
virtual std::string format_bn (const BigInt &bn) const =0

Detailed Description

Format ASN.1 data and call a virtual to format

Definition at line 23 of file asn1_print.h.

Constructor & Destructor Documentation

◆ ~ASN1_Formatter()

virtual Botan::ASN1_Formatter::~ASN1_Formatter ( )
virtualdefault

◆ ASN1_Formatter()

Botan::ASN1_Formatter::ASN1_Formatter ( bool print_context_specific,
size_t max_depth,
bool require_der = false )
inline

Create a formatter with the given settings

Parameters
print_context_specificif true, try to parse nested context specific data.
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 35 of file asn1_print.h.

35 :
36 m_print_context_specific(print_context_specific), m_max_depth(max_depth), m_require_der(require_der) {}

Referenced by Botan::ASN1_Pretty_Printer::ASN1_Pretty_Printer().

Member Function Documentation

◆ format()

virtual std::string Botan::ASN1_Formatter::format ( ASN1_Type type_tag,
ASN1_Class class_tag,
size_t level,
size_t length,
std::string_view value ) const
protectedpure virtual

This is called for each element

◆ format_bin()

virtual std::string Botan::ASN1_Formatter::format_bin ( ASN1_Type type_tag,
ASN1_Class class_tag,
const std::vector< uint8_t > & vec ) const
protectedpure virtual

This is called to format binary elements that we don't know how to convert to a string. The result will be passed as value to format; the tags are included as a hint to aid decoding.

TODO(Botan4) change the vector to a span

◆ format_bn()

virtual std::string Botan::ASN1_Formatter::format_bn ( const BigInt & bn) const
protectedpure virtual

This is called to format integers

◆ print() [1/2]

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

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

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

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: