Botan 1.10.17

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,
22 CONTEXT_SPECIFIC = 0x80,
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,
39 NUMERIC_STRING = 0x12,
40 PRINTABLE_STRING = 0x13,
41 T61_STRING = 0x14,
42 IA5_STRING = 0x16,
43 VISIBLE_STRING = 0x1A,
44 BMP_STRING = 0x1E,
45
46 UTC_TIME = 0x17,
47 GENERALIZED_TIME = 0x18,
48
49 NO_OBJECT = 0xFF00,
50 DIRECTORY_STRING = 0xFF01
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;
83 SecureVector<byte> value;
84 };
85
86 /*
87 * ASN.1 Utility Functions
88 */
89 class DataSource;
90
91 namespace ASN1 {
92
93 SecureVector<byte> put_in_sequence(const MemoryRegion<byte>& val);
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
Botan::INTEGER
Definition: asn1_int.h:29
Botan::BMP_STRING
Definition: asn1_int.h:44
Botan::OBJECT_ID
Definition: asn1_int.h:33
Botan::CONTEXT_SPECIFIC
Definition: asn1_int.h:22
Botan::ASN1_Object
Definition: asn1_int.h:56
Botan::ASN1_Object::~ASN1_Object
virtual ~ASN1_Object()
Definition: asn1_int.h:71
Botan::ASN1::maybe_BER
bool maybe_BER(DataSource &source)
Definition: asn1_int.cpp:55
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_int.cpp:46
Botan::PRINTABLE_STRING
Definition: asn1_int.h:40
Botan::DataSource
Definition: data_src.h:20
Botan::ENUMERATED
Definition: asn1_int.h:34
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::OCTET_STRING
Definition: asn1_int.h:31
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::PRIVATE
Definition: asn1_int.h:23
Botan::CONSTRUCTED
Definition: asn1_int.h:25
Botan::T61_STRING
Definition: asn1_int.h:41
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_int.h:19
Botan::Decoding_Error
Definition: exceptn.h:138
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::BER_Object::value
SecureVector< byte > value
Definition: asn1_int.h:83
Botan::DIRECTORY_STRING
Definition: asn1_int.h:50
Botan::NULL_TAG
Definition: asn1_int.h:32
Botan::UTC_TIME
Definition: asn1_int.h:46
Botan::ASN1::put_in_sequence
SecureVector< byte > put_in_sequence(const MemoryRegion< byte > &contents)
Definition: asn1_int.cpp:34
Botan::VISIBLE_STRING
Definition: asn1_int.h:43
Botan::APPLICATION
Definition: asn1_int.h:21
Botan::SET
Definition: asn1_int.h:36
Botan::BER_Object::type_tag
ASN1_Tag type_tag
Definition: asn1_int.h:82
Botan::BIT_STRING
Definition: asn1_int.h:30
Botan::NO_OBJECT
Definition: asn1_int.h:49
Botan::GENERALIZED_TIME
Definition: asn1_int.h:47
Botan::BER_Decoding_Error
Definition: asn1_int.h:107
Botan::BOOLEAN
Definition: asn1_int.h:28
Botan::NUMERIC_STRING
Definition: asn1_int.h:39
Botan::UTF8_STRING
Definition: asn1_int.h:38
Botan::SecureVector< byte >
Botan::EOC
Definition: asn1_int.h:27
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::BER_Object
Definition: asn1_int.h:77
Botan::BER_Bad_Tag
Definition: asn1_int.h:115
Botan::IA5_STRING
Definition: asn1_int.h:42