Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

asn1_print.h
Go to the documentation of this file.
1 /*
2 * (C) 2014,2015,2017 Jack Lloyd
3 *
4 * Botan is released under the Simplified BSD License (see license.txt)
5 */
6
7 #ifndef BOTAN_ASN1_PRINT_H_
8 #define BOTAN_ASN1_PRINT_H_
9
10 #include <botan/asn1_obj.h>
11 #include <string>
12 #include <vector>
13 #include <iosfwd>
14
15 namespace Botan {
16
17 class BER_Decoder;
18
19 /**
20 * Format ASN.1 data and call a virtual to format
21 */
22 class BOTAN_PUBLIC_API(2,4) ASN1_Formatter
23 {
24 public:
25 virtual ~ASN1_Formatter() = default;
26
27 /**
28 * @param print_context_specific if true, try to parse nested context specific data.
29 * @param max_depth do not recurse more than this many times. If zero, recursion
30 * is unbounded.
31 */
32 ASN1_Formatter(bool print_context_specific, size_t max_depth) :
33 m_print_context_specific(print_context_specific),
34 m_max_depth(max_depth)
35 {}
36
37 void print_to_stream(std::ostream& out,
38 const uint8_t in[],
39 size_t len) const;
40
41 std::string print(const uint8_t in[], size_t len) const;
42
43 template<typename Alloc>
44 std::string print(const std::vector<uint8_t, Alloc>& vec) const
45 {
46 return print(vec.data(), vec.size());
47 }
48
49 protected:
50 /**
51 * This is called for each element
52 */
53 virtual std::string format(ASN1_Tag type_tag,
54 ASN1_Tag class_tag,
55 size_t level,
56 size_t length,
57 const std::string& value) const = 0;
58
59 /**
60 * This is called to format binary elements that we don't know how to
61 * convert to a string The result will be passed as value to format; the
62 * tags are included as a hint to aid decoding.
63 */
64 virtual std::string format_bin(ASN1_Tag type_tag,
65 ASN1_Tag class_tag,
66 const std::vector<uint8_t>& vec) const = 0;
67
68 private:
69 void decode(std::ostream& output,
70 BER_Decoder& decoder,
71 size_t level) const;
72
73 const bool m_print_context_specific;
74 const size_t m_max_depth;
75 };
76
77 /**
78 * Format ASN.1 data into human readable output. The exact form of the output for
79 * any particular input is not guaranteed and may change from release to release.
80 */
81 class BOTAN_PUBLIC_API(2,4) ASN1_Pretty_Printer final : public ASN1_Formatter
82 {
83 public:
84 /**
85 * @param print_limit strings larger than this are not printed
86 * @param print_binary_limit binary strings larger than this are not printed
87 * @param print_context_specific if true, try to parse nested context specific data.
88 * @param initial_level the initial depth (0 or 1 are the only reasonable values)
89 * @param value_column ASN.1 values are lined up at this column in output
90 * @param max_depth do not recurse more than this many times. If zero, recursion
91 * is unbounded.
92 */
93 ASN1_Pretty_Printer(size_t print_limit = 4096,
94 size_t print_binary_limit = 2048,
95 bool print_context_specific = true,
96 size_t initial_level = 0,
97 size_t value_column = 60,
98 size_t max_depth = 64) :
99 ASN1_Formatter(print_context_specific, max_depth),
100 m_print_limit(print_limit),
101 m_print_binary_limit(print_binary_limit),
102 m_initial_level(initial_level),
103 m_value_column(value_column)
104 {}
105
106 private:
107 std::string format(ASN1_Tag type_tag,
108 ASN1_Tag class_tag,
109 size_t level,
110 size_t length,
111 const std::string& value) const override;
112
113 std::string format_bin(ASN1_Tag type_tag,
114 ASN1_Tag class_tag,
115 const std::vector<uint8_t>& vec) const override;
116
117 const size_t m_print_limit;
118 const size_t m_print_binary_limit;
119 const size_t m_initial_level;
120 const size_t m_value_column;
121 };
122
123 }
124
125 #endif
Botan::ASN1_Formatter
Definition: asn1_print.h:22
Botan::ASN1_Formatter::ASN1_Formatter
ASN1_Formatter(bool print_context_specific, size_t max_depth)
Definition: asn1_print.h:32
Botan::ASN1_Pretty_Printer::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)
Definition: asn1_print.h:93
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:23
Botan::PEM_Code::decode
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:68
Botan
Definition: alg_id.cpp:13
Botan::ASN1_Pretty_Printer
Definition: asn1_print.h:81
Botan::ASN1_Formatter::print
std::string print(const std::vector< uint8_t, Alloc > &vec) const
Definition: asn1_print.h:44
Botan::BER_Decoder
Definition: ber_dec.h:21