monotone

monotone Mtn Source Tree

Root/botan/asn1_obj.h

1/*************************************************
2* Common ASN.1 Objects Header File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_ASN1_OBJ_H__
7#define BOTAN_ASN1_OBJ_H__
8
9#include <botan/asn1.h>
10#include <map>
11#include <vector>
12
13namespace Botan {
14
15/*************************************************
16* Algorithm Identifier *
17*************************************************/
18class AlgorithmIdentifier
19 {
20 public:
21 OID oid;
22 SecureVector<byte> parameters;
23
24 AlgorithmIdentifier() {}
25 AlgorithmIdentifier(const OID&, const MemoryRegion<byte>&);
26 AlgorithmIdentifier(const std::string&, bool = true);
27 };
28
29/*************************************************
30* Extension *
31*************************************************/
32class Extension
33 {
34 public:
35 bool critical;
36 OID oid;
37 SecureVector<byte> value;
38
39 Extension() { critical = false; }
40 Extension(const OID&, const MemoryRegion<byte>&);
41 Extension(const std::string&, const MemoryRegion<byte>&);
42 };
43
44/*************************************************
45* Attribute *
46*************************************************/
47class Attribute
48 {
49 public:
50 OID oid;
51 SecureVector<byte> parameters;
52
53 Attribute() {}
54 Attribute(const OID&, const MemoryRegion<byte>&);
55 Attribute(const std::string&, const MemoryRegion<byte>&);
56 };
57
58/*************************************************
59* X.509 Time *
60*************************************************/
61class X509_Time
62 {
63 public:
64 std::string as_string() const;
65 std::string readable_string() const;
66 bool time_is_set() const;
67
68 ASN1_Tag tagging() const;
69
70 s32bit cmp(const X509_Time&) const;
71 s32bit cmp(u64bit) const;
72
73 X509_Time(u64bit);
74 X509_Time(const std::string& = "");
75 X509_Time(const std::string&, ASN1_Tag);
76 private:
77 bool passes_sanity_check() const;
78 u32bit year, month, day, hour, minute, second;
79 ASN1_Tag tag;
80 };
81
82/*************************************************
83* Simple String *
84*************************************************/
85class ASN1_String
86 {
87 public:
88 std::string value() const;
89 std::string iso_8859() const;
90
91 ASN1_Tag tagging() const;
92
93 ASN1_String(const std::string& = "");
94 ASN1_String(const std::string&, ASN1_Tag);
95 private:
96 std::string iso_8859_str;
97 ASN1_Tag tag;
98 };
99
100/*************************************************
101* Distinguished Name *
102*************************************************/
103class X509_DN
104 {
105 public:
106 std::multimap<OID, std::string> get_attributes() const;
107 std::vector<std::string> get_attribute(const std::string&) const;
108
109 void add_attribute(const std::string&, const std::string&);
110 void add_attribute(const OID&, const std::string&);
111
112 static std::string deref_info_field(const std::string&);
113
114 void do_decode(const MemoryRegion<byte>&);
115 SecureVector<byte> get_bits() const;
116
117 X509_DN();
118 X509_DN(const std::multimap<OID, std::string>&);
119 X509_DN(const std::multimap<std::string, std::string>&);
120 private:
121 std::multimap<OID, ASN1_String> dn_info;
122 SecureVector<byte> dn_bits;
123 };
124
125/*************************************************
126* Alternative Name *
127*************************************************/
128class AlternativeName
129 {
130 public:
131 void add_attribute(const std::string&, const std::string&);
132 std::multimap<std::string, std::string> get_attributes() const;
133
134 void add_othername(const OID&, const std::string&, ASN1_Tag);
135 std::multimap<OID, ASN1_String> get_othernames() const;
136
137 bool has_items() const;
138
139 AlternativeName(const std::string& = "", const std::string& = "",
140 const std::string& = "");
141 private:
142 std::multimap<std::string, std::string> alt_info;
143 std::multimap<OID, ASN1_String> othernames;
144 };
145
146/*************************************************
147* Comparison Operations *
148*************************************************/
149bool operator==(const AlgorithmIdentifier&, const AlgorithmIdentifier&);
150bool operator!=(const AlgorithmIdentifier&, const AlgorithmIdentifier&);
151
152bool operator==(const X509_Time&, const X509_Time&);
153bool operator!=(const X509_Time&, const X509_Time&);
154bool operator<=(const X509_Time&, const X509_Time&);
155bool operator>=(const X509_Time&, const X509_Time&);
156
157bool operator==(const X509_DN&, const X509_DN&);
158bool operator!=(const X509_DN&, const X509_DN&);
159bool operator<(const X509_DN&, const X509_DN&);
160
161s32bit validity_check(const X509_Time&, const X509_Time&, u64bit);
162
163bool is_string_type(ASN1_Tag);
164
165/*************************************************
166* DER Encoding Functions *
167*************************************************/
168namespace DER {
169
170void encode(DER_Encoder&, const AlgorithmIdentifier&);
171void encode(DER_Encoder&, const Extension&);
172void encode(DER_Encoder&, const Attribute&);
173void encode(DER_Encoder&, const X509_Time&);
174void encode(DER_Encoder&, const X509_Time&, ASN1_Tag);
175void encode(DER_Encoder&, const ASN1_String&);
176void encode(DER_Encoder&, const ASN1_String&,
177 ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC);
178void encode(DER_Encoder&, const X509_DN&);
179void encode(DER_Encoder&, const AlternativeName&);
180void encode(DER_Encoder&, Key_Constraints);
181
182}
183
184/*************************************************
185* BER Decoding Functions *
186*************************************************/
187namespace BER {
188
189void decode(BER_Decoder&, AlgorithmIdentifier&);
190void decode(BER_Decoder&, Extension&);
191void decode(BER_Decoder&, Attribute&);
192void decode(BER_Decoder&, X509_Time&);
193void decode(BER_Decoder&, ASN1_String&);
194void decode(BER_Decoder&, ASN1_String&, ASN1_Tag, ASN1_Tag);
195void decode(BER_Decoder&, X509_DN&);
196void decode(BER_Decoder&, AlternativeName&);
197void decode(BER_Decoder&, Key_Constraints&);
198
199}
200
201/*************************************************
202* Insert a key/value pair into a multimap *
203*************************************************/
204template<typename K, typename V>
205void multimap_insert(std::multimap<K, V>& multimap,
206 const K& key, const V& value)
207 {
208 multimap.insert(std::make_pair(key, value));
209 }
210
211}
212
213#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status