Botan  1.10.9
asn1_int.h
Go to the documentation of this file.
1 /*
2 * ASN.1 Internals
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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 /**
17 * ASN.1 Type and Class Tags
18 */
19 enum ASN1_Tag {
20  UNIVERSAL = 0x00,
21  APPLICATION = 0x40,
23  PRIVATE = 0xC0,
24 
25  CONSTRUCTED = 0x20,
26 
27  EOC = 0x00,
28  BOOLEAN = 0x01,
29  INTEGER = 0x02,
30  BIT_STRING = 0x03,
31  OCTET_STRING = 0x04,
32  NULL_TAG = 0x05,
33  OBJECT_ID = 0x06,
34  ENUMERATED = 0x0A,
35  SEQUENCE = 0x10,
36  SET = 0x11,
37 
38  UTF8_STRING = 0x0C,
41  T61_STRING = 0x14,
42  IA5_STRING = 0x16,
44  BMP_STRING = 0x1E,
45 
46  UTC_TIME = 0x17,
48 
49  NO_OBJECT = 0xFF00,
51 };
52 
53 /**
54 * Basic ASN.1 Object Interface
55 */
56 class BOTAN_DLL ASN1_Object
57  {
58  public:
59  /**
60  * Encode whatever this object is into to
61  * @param to the DER_Encoder that will be written to
62  */
63  virtual void encode_into(class DER_Encoder& to) const = 0;
64 
65  /**
66  * Decode whatever this object is from from
67  * @param from the BER_Decoder that will be read from
68  */
69  virtual void decode_from(class BER_Decoder& from) = 0;
70 
71  virtual ~ASN1_Object() {}
72  };
73 
74 /**
75 * BER Encoded Object
76 */
77 class BOTAN_DLL BER_Object
78  {
79  public:
80  void assert_is_a(ASN1_Tag, ASN1_Tag);
81 
82  ASN1_Tag type_tag, class_tag;
84  };
85 
86 /*
87 * ASN.1 Utility Functions
88 */
89 class DataSource;
90 
91 namespace ASN1 {
92 
94 std::string to_string(const BER_Object& obj);
95 
96 /**
97 * Heuristics tests; is this object possibly BER?
98 * @param src a data source that will be peeked at but not modified
99 */
100 bool maybe_BER(DataSource& src);
101 
102 }
103 
104 /**
105 * General BER Decoding Error Exception
106 */
107 struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error
108  {
109  BER_Decoding_Error(const std::string&);
110  };
111 
112 /**
113 * Exception For Incorrect BER Taggings
114 */
115 struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error
116  {
117  BER_Bad_Tag(const std::string& msg, ASN1_Tag tag);
118  BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2);
119  };
120 
121 }
122 
123 #endif
virtual ~ASN1_Object()
Definition: asn1_int.h:71
bool maybe_BER(DataSource &source)
Definition: asn1_int.cpp:55
std::string to_string(const BER_Object &obj)
Definition: asn1_int.cpp:46
ASN1_Tag
Definition: asn1_int.h:19
SecureVector< byte > value
Definition: asn1_int.h:83
SecureVector< byte > put_in_sequence(const MemoryRegion< byte > &contents)
Definition: asn1_int.cpp:34
ASN1_Tag type_tag
Definition: asn1_int.h:82