Botan  2.4.0
Crypto and TLS for C++11
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 : uint32_t {
23  UNIVERSAL = 0x00,
24  APPLICATION = 0x40,
26 
27  CONSTRUCTED = 0x20,
28 
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,
45  T61_STRING = 0x14,
46  IA5_STRING = 0x16,
49  BMP_STRING = 0x1E,
50 
51  UTC_TIME = 0x17,
54 
55  NO_OBJECT = 0xFF00,
57 };
58 
59 std::string BOTAN_DLL asn1_tag_to_string(ASN1_Tag type);
60 
61 /**
62 * Basic ASN.1 Object Interface
63 */
65  {
66  public:
67  /**
68  * Encode whatever this object is into to
69  * @param to the DER_Encoder that will be written to
70  */
71  virtual void encode_into(DER_Encoder& to) const = 0;
72 
73  /**
74  * Decode whatever this object is from from
75  * @param from the BER_Decoder that will be read from
76  */
77  virtual void decode_from(BER_Decoder& from) = 0;
78 
79  ASN1_Object() = default;
80  ASN1_Object(const ASN1_Object&) = default;
81  ASN1_Object & operator=(const ASN1_Object&) = default;
82  virtual ~ASN1_Object() = default;
83  };
84 
85 /**
86 * BER Encoded Object
87 */
88 class BOTAN_PUBLIC_API(2,0) BER_Object final
89  {
90  public:
91  void assert_is_a(ASN1_Tag type_tag, ASN1_Tag class_tag) const;
92 
93  // public member variable:
94  ASN1_Tag type_tag, class_tag;
95 
96  // public member variable:
98  };
99 
100 /*
101 * ASN.1 Utility Functions
102 */
103 class DataSource;
104 
105 namespace ASN1 {
106 
107 std::vector<uint8_t> put_in_sequence(const std::vector<uint8_t>& val);
108 std::string to_string(const BER_Object& obj);
109 
110 /**
111 * Heuristics tests; is this object possibly BER?
112 * @param src a data source that will be peeked at but not modified
113 */
114 bool maybe_BER(DataSource& src);
115 
116 }
117 
118 /**
119 * General BER Decoding Error Exception
120 */
122  {
123  public:
124  explicit BER_Decoding_Error(const std::string&);
125  };
126 
127 /**
128 * Exception For Incorrect BER Taggings
129 */
131  {
132  public:
133  BER_Bad_Tag(const std::string& msg, ASN1_Tag tag);
134  BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2);
135  };
136 
137 }
138 
139 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string asn1_tag_to_string(ASN1_Tag type)
Definition: asn1_obj.cpp:15
bool maybe_BER(DataSource &source)
Definition: asn1_obj.cpp:116
ASN1_Tag
Definition: asn1_obj.h:22
MechanismType type
secure_vector< uint8_t > value
Definition: asn1_obj.h:97
Definition: alg_id.cpp:13
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition: asn1_obj.cpp:96
ASN1_Tag type_tag
Definition: asn1_obj.h:94
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88