Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

asn1_obj.h
Go to the documentation of this file.
1 /*
2 * ASN.1 Internals
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_ASN1_H__
9 #define BOTAN_ASN1_H__
10
11 #include <botan/secmem.h>
12 #include <botan/exceptn.h>
13
14 namespace Botan {
15
16 class BER_Decoder;
17 class DER_Encoder;
18
19 /**
20 * ASN.1 Type and Class Tags
21 */
22 enum ASN1_Tag {
23 UNIVERSAL = 0x00,
24 APPLICATION = 0x40,
25 CONTEXT_SPECIFIC = 0x80,
26
27 CONSTRUCTED = 0x20,
28
29 PRIVATE = CONSTRUCTED | CONTEXT_SPECIFIC,
30
31 EOC = 0x00,
32 BOOLEAN = 0x01,
33 INTEGER = 0x02,
34 BIT_STRING = 0x03,
35 OCTET_STRING = 0x04,
36 NULL_TAG = 0x05,
37 OBJECT_ID = 0x06,
38 ENUMERATED = 0x0A,
39 SEQUENCE = 0x10,
40 SET = 0x11,
41
42 UTF8_STRING = 0x0C,
43 NUMERIC_STRING = 0x12,
44 PRINTABLE_STRING = 0x13,
45 T61_STRING = 0x14,
46 IA5_STRING = 0x16,
47 VISIBLE_STRING = 0x1A,
48 BMP_STRING = 0x1E,
49
50 UTC_TIME = 0x17,
51 GENERALIZED_TIME = 0x18,
52 UTC_OR_GENERALIZED_TIME = 0x19,
53
54 NO_OBJECT = 0xFF00,
55 DIRECTORY_STRING = 0xFF01
56 };
57
58 /**
59 * Basic ASN.1 Object Interface
60 */
61 class BOTAN_DLL ASN1_Object
62 {
63 public:
64 /**
65 * Encode whatever this object is into to
66 * @param to the DER_Encoder that will be written to
67 */
68 virtual void encode_into(DER_Encoder& to) const = 0;
69
70 /**
71 * Decode whatever this object is from from
72 * @param from the BER_Decoder that will be read from
73 */
74 virtual void decode_from(BER_Decoder& from) = 0;
75
76 ASN1_Object() = default;
77 ASN1_Object(const ASN1_Object&) = default;
78 ASN1_Object & operator=(const ASN1_Object&) = default;
79 virtual ~ASN1_Object() = default;
80 };
81
82 /**
83 * BER Encoded Object
84 */
85 class BOTAN_DLL BER_Object
86 {
87 public:
88 void assert_is_a(ASN1_Tag, ASN1_Tag);
89
90 // public member variable:
91 ASN1_Tag type_tag, class_tag;
92
93 // public member variable:
94 secure_vector<uint8_t> value;
95 };
96
97 /*
98 * ASN.1 Utility Functions
99 */
100 class DataSource;
101
102 namespace ASN1 {
103
104 std::vector<uint8_t> put_in_sequence(const std::vector<uint8_t>& val);
105 std::string to_string(const BER_Object& obj);
106
107 /**
108 * Heuristics tests; is this object possibly BER?
109 * @param src a data source that will be peeked at but not modified
110 */
111 bool maybe_BER(DataSource& src);
112
113 }
114
115 /**
116 * General BER Decoding Error Exception
117 */
118 struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error
119 {
120 explicit BER_Decoding_Error(const std::string&);
121 };
122
123 /**
124 * Exception For Incorrect BER Taggings
125 */
126 struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error
127 {
128 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag);
129 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2);
130 };
131
132 }
133
134 #endif
Botan::INTEGER
Definition: asn1_obj.h:33
Botan::BMP_STRING
Definition: asn1_obj.h:48
Botan::OBJECT_ID
Definition: asn1_obj.h:37
Botan::CONTEXT_SPECIFIC
Definition: asn1_obj.h:25
Botan::UTC_OR_GENERALIZED_TIME
Definition: asn1_obj.h:52
Botan::ASN1_Object
Definition: asn1_obj.h:61
Botan::ASN1::maybe_BER
bool maybe_BER(DataSource &source)
Definition: asn1_obj.cpp:55
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::PRINTABLE_STRING
Definition: asn1_obj.h:44
Botan::DataSource
Definition: data_src.h:21
Botan::ENUMERATED
Definition: asn1_obj.h:38
Botan::UNIVERSAL
Definition: asn1_obj.h:23
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::PRIVATE
Definition: asn1_obj.h:29
Botan::BER_Object::value
secure_vector< uint8_t > value
Definition: asn1_obj.h:94
Botan::CONSTRUCTED
Definition: asn1_obj.h:27
Botan::T61_STRING
Definition: asn1_obj.h:45
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:22
Botan::Decoding_Error
Definition: exceptn.h:189
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan
Definition: alg_id.cpp:13
Botan::DIRECTORY_STRING
Definition: asn1_obj.h:55
Botan::NULL_TAG
Definition: asn1_obj.h:36
Botan::ASN1::put_in_sequence
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition: asn1_obj.cpp:35
Botan::UTC_TIME
Definition: asn1_obj.h:50
Botan::VISIBLE_STRING
Definition: asn1_obj.h:47
Botan::APPLICATION
Definition: asn1_obj.h:24
Botan::SET
Definition: asn1_obj.h:40
Botan::BER_Object::type_tag
ASN1_Tag type_tag
Definition: asn1_obj.h:91
Botan::BIT_STRING
Definition: asn1_obj.h:34
Botan::NO_OBJECT
Definition: asn1_obj.h:54
Botan::GENERALIZED_TIME
Definition: asn1_obj.h:51
Botan::BER_Decoding_Error
Definition: asn1_obj.h:118
Botan::BOOLEAN
Definition: asn1_obj.h:32
Botan::NUMERIC_STRING
Definition: asn1_obj.h:43
Botan::UTF8_STRING
Definition: asn1_obj.h:42
Botan::EOC
Definition: asn1_obj.h:31
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::BER_Object
Definition: asn1_obj.h:85
Botan::BER_Bad_Tag
Definition: asn1_obj.h:126
Botan::IA5_STRING
Definition: asn1_obj.h:46