/src/botan/build/include/botan/ber_dec.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * BER Decoder |
3 | | * (C) 1999-2010,2018 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_BER_DECODER_H_ |
9 | | #define BOTAN_BER_DECODER_H_ |
10 | | |
11 | | #include <botan/asn1_obj.h> |
12 | | #include <botan/data_src.h> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | class BigInt; |
17 | | |
18 | | /** |
19 | | * BER Decoding Object |
20 | | */ |
21 | | class BOTAN_PUBLIC_API(2,0) BER_Decoder final |
22 | | { |
23 | | public: |
24 | | /** |
25 | | * Set up to BER decode the data in buf of length len |
26 | | */ |
27 | | BER_Decoder(const uint8_t buf[], size_t len); |
28 | | |
29 | | /** |
30 | | * Set up to BER decode the data in vec |
31 | | */ |
32 | | explicit BER_Decoder(const secure_vector<uint8_t>& vec); |
33 | | |
34 | | /** |
35 | | * Set up to BER decode the data in vec |
36 | | */ |
37 | | explicit BER_Decoder(const std::vector<uint8_t>& vec); |
38 | | |
39 | | /** |
40 | | * Set up to BER decode the data in src |
41 | | */ |
42 | | explicit BER_Decoder(DataSource& src); |
43 | | |
44 | | /** |
45 | | * Set up to BER decode the data in obj |
46 | | */ |
47 | | BER_Decoder(const BER_Object& obj) : |
48 | 31.9k | BER_Decoder(obj.bits(), obj.length()) {} |
49 | | |
50 | | /** |
51 | | * Set up to BER decode the data in obj |
52 | | */ |
53 | | BER_Decoder(BER_Object&& obj) : |
54 | 10.5k | BER_Decoder(std::move(obj), nullptr) {} |
55 | | |
56 | | BER_Decoder(const BER_Decoder& other); |
57 | | |
58 | | BER_Decoder& operator=(const BER_Decoder&) = delete; |
59 | | |
60 | | /** |
61 | | * Get the next object in the data stream. |
62 | | * If EOF, returns an object with type NO_OBJECT. |
63 | | */ |
64 | | BER_Object get_next_object(); |
65 | | |
66 | | BER_Decoder& get_next(BER_Object& ber) |
67 | 26.4k | { |
68 | 26.4k | ber = get_next_object(); |
69 | 26.4k | return (*this); |
70 | 26.4k | } |
71 | | |
72 | | /** |
73 | | * Push an object back onto the stream. Throws if another |
74 | | * object was previously pushed and has not been subsequently |
75 | | * read out. |
76 | | */ |
77 | | void push_back(const BER_Object& obj); |
78 | | |
79 | | /** |
80 | | * Push an object back onto the stream. Throws if another |
81 | | * object was previously pushed and has not been subsequently |
82 | | * read out. |
83 | | */ |
84 | | void push_back(BER_Object&& obj); |
85 | | |
86 | | /** |
87 | | * Return true if there is at least one more item remaining |
88 | | */ |
89 | | bool more_items() const; |
90 | | |
91 | | /** |
92 | | * Verify the stream is concluded, throws otherwise. |
93 | | * Returns (*this) |
94 | | */ |
95 | | BER_Decoder& verify_end(); |
96 | | |
97 | | /** |
98 | | * Verify the stream is concluded, throws otherwise. |
99 | | * Returns (*this) |
100 | | */ |
101 | | BER_Decoder& verify_end(const std::string& err_msg); |
102 | | |
103 | | /** |
104 | | * Discard any data that remains unread |
105 | | * Returns (*this) |
106 | | */ |
107 | | BER_Decoder& discard_remaining(); |
108 | | |
109 | | BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag); |
110 | | |
111 | | BER_Decoder start_sequence() |
112 | 418k | { |
113 | 418k | return start_cons(ASN1_Type::Sequence, ASN1_Class::Universal); |
114 | 418k | } |
115 | | |
116 | | BER_Decoder start_set() |
117 | 115k | { |
118 | 115k | return start_cons(ASN1_Type::Set, ASN1_Class::Universal); |
119 | 115k | } |
120 | | |
121 | | BER_Decoder start_context_specific(uint32_t tag) |
122 | 6.11k | { |
123 | 6.11k | return start_cons(ASN1_Type(tag), ASN1_Class::ContextSpecific); |
124 | 6.11k | } |
125 | | |
126 | | BER_Decoder start_explicit_context_specific(uint32_t tag) |
127 | 0 | { |
128 | 0 | return start_cons(ASN1_Type(tag), ASN1_Class::ExplicitContextSpecific); |
129 | 0 | } |
130 | | |
131 | | /** |
132 | | * Finish decoding a constructed data, throws if any data remains. |
133 | | * Returns the parent of *this (ie the object on which start_cons was called). |
134 | | */ |
135 | | BER_Decoder& end_cons(); |
136 | | |
137 | | /** |
138 | | * Get next object and copy value to POD type |
139 | | * Asserts value length is equal to POD type sizeof. |
140 | | * Asserts Type tag and optional Class tag according to parameters. |
141 | | * Copy value to POD type (struct, union, C-style array, std::array, etc.). |
142 | | * @param out POD type reference where to copy object value |
143 | | * @param type_tag ASN1_Type enum to assert type on object read |
144 | | * @param class_tag ASN1_Type enum to assert class on object read (default: CONTEXT_SPECIFIC) |
145 | | * @return this reference |
146 | | */ |
147 | | template <typename T> |
148 | | BER_Decoder& get_next_value(T &out, |
149 | | ASN1_Type type_tag, |
150 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific) |
151 | | { |
152 | | static_assert(std::is_standard_layout<T>::value && std::is_trivial<T>::value, "Type must be POD"); |
153 | | |
154 | | BER_Object obj = get_next_object(); |
155 | | obj.assert_is_a(type_tag, class_tag); |
156 | | |
157 | | if (obj.length() != sizeof(T)) |
158 | | throw BER_Decoding_Error( |
159 | | "Size mismatch. Object value size is " + |
160 | | std::to_string(obj.length()) + |
161 | | "; Output type size is " + |
162 | | std::to_string(sizeof(T))); |
163 | | |
164 | | copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length()); |
165 | | |
166 | | return (*this); |
167 | | } |
168 | | |
169 | | /* |
170 | | * Save all the bytes remaining in the source |
171 | | */ |
172 | | template<typename Alloc> |
173 | | BER_Decoder& raw_bytes(std::vector<uint8_t, Alloc>& out) |
174 | 139k | { |
175 | 139k | out.clear(); |
176 | 139k | uint8_t buf; |
177 | 12.4M | while(m_source->read_byte(buf)) |
178 | 12.2M | out.push_back(buf); |
179 | 139k | return (*this); |
180 | 139k | } |
181 | | |
182 | | BER_Decoder& decode_null(); |
183 | | |
184 | | /** |
185 | | * Decode a BER encoded BOOLEAN |
186 | | */ |
187 | | BER_Decoder& decode(bool& out) |
188 | 690 | { |
189 | 690 | return decode(out, ASN1_Type::Boolean, ASN1_Class::Universal); |
190 | 690 | } |
191 | | |
192 | | /* |
193 | | * Decode a small BER encoded INTEGER |
194 | | */ |
195 | | BER_Decoder& decode(size_t& out) |
196 | 12.2k | { |
197 | 12.2k | return decode(out, ASN1_Type::Integer, ASN1_Class::Universal); |
198 | 12.2k | } |
199 | | |
200 | | /* |
201 | | * Decode a BER encoded INTEGER |
202 | | */ |
203 | | BER_Decoder& decode(BigInt& out) |
204 | 47.9k | { |
205 | 47.9k | return decode(out, ASN1_Type::Integer, ASN1_Class::Universal); |
206 | 47.9k | } |
207 | | |
208 | | std::vector<uint8_t> get_next_octet_string() |
209 | 2.33k | { |
210 | 2.33k | std::vector<uint8_t> out_vec; |
211 | 2.33k | decode(out_vec, ASN1_Type::OctetString); |
212 | 2.33k | return out_vec; |
213 | 2.33k | } |
214 | | |
215 | | /* |
216 | | * BER decode a BIT STRING or OCTET STRING |
217 | | */ |
218 | | template<typename Alloc> |
219 | | BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Type real_type) |
220 | 115k | { |
221 | 115k | return decode(out, real_type, real_type, ASN1_Class::Universal); |
222 | 115k | } Botan::BER_Decoder& Botan::BER_Decoder::decode<std::__1::allocator<unsigned char> >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, Botan::ASN1_Type) Line | Count | Source | 220 | 110k | { | 221 | 110k | return decode(out, real_type, real_type, ASN1_Class::Universal); | 222 | 110k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode<Botan::secure_allocator<unsigned char> >(std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> >&, Botan::ASN1_Type) Line | Count | Source | 220 | 4.97k | { | 221 | 4.97k | return decode(out, real_type, real_type, ASN1_Class::Universal); | 222 | 4.97k | } |
|
223 | | |
224 | | BER_Decoder& decode(bool& v, |
225 | | ASN1_Type type_tag, |
226 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
227 | | |
228 | | BER_Decoder& decode(size_t& v, |
229 | | ASN1_Type type_tag, |
230 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
231 | | |
232 | | BER_Decoder& decode(BigInt& v, |
233 | | ASN1_Type type_tag, |
234 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
235 | | |
236 | | BER_Decoder& decode(std::vector<uint8_t>& v, |
237 | | ASN1_Type real_type, |
238 | | ASN1_Type type_tag, |
239 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
240 | | |
241 | | BER_Decoder& decode(secure_vector<uint8_t>& v, |
242 | | ASN1_Type real_type, |
243 | | ASN1_Type type_tag, |
244 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
245 | | |
246 | | BER_Decoder& decode(class ASN1_Object& obj, |
247 | | ASN1_Type type_tag = ASN1_Type::NoObject, |
248 | | ASN1_Class class_tag = ASN1_Class::NoObject); |
249 | | |
250 | | /** |
251 | | * Decode an integer value which is typed as an octet string |
252 | | */ |
253 | | BER_Decoder& decode_octet_string_bigint(BigInt& b); |
254 | | |
255 | | uint64_t decode_constrained_integer(ASN1_Type type_tag, |
256 | | ASN1_Class class_tag, |
257 | | size_t T_bytes); |
258 | | |
259 | | template<typename T> BER_Decoder& decode_integer_type(T& out) |
260 | 0 | { |
261 | 0 | return decode_integer_type<T>(out, ASN1_Type::Integer, ASN1_Class::Universal); |
262 | 0 | } Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned long>(unsigned long&) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned char>(unsigned char&) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned short>(unsigned short&) |
263 | | |
264 | | template<typename T> |
265 | | BER_Decoder& decode_integer_type(T& out, |
266 | | ASN1_Type type_tag, |
267 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific) |
268 | 0 | { |
269 | 0 | out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out))); |
270 | 0 | return (*this); |
271 | 0 | } Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned long>(unsigned long&, Botan::ASN1_Type, Botan::ASN1_Class) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned char>(unsigned char&, Botan::ASN1_Type, Botan::ASN1_Class) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned short>(unsigned short&, Botan::ASN1_Type, Botan::ASN1_Class) |
272 | | |
273 | | template<typename T> |
274 | | BER_Decoder& decode_optional(T& out, |
275 | | ASN1_Type type_tag, |
276 | | ASN1_Class class_tag, |
277 | | const T& default_value = T()); |
278 | | |
279 | | template<typename T> |
280 | | BER_Decoder& decode_optional_implicit( |
281 | | T& out, |
282 | | ASN1_Type type_tag, |
283 | | ASN1_Class class_tag, |
284 | | ASN1_Type real_type, |
285 | | ASN1_Class real_class, |
286 | | const T& default_value = T()); |
287 | | |
288 | | template<typename T> |
289 | | BER_Decoder& decode_list(std::vector<T>& out, |
290 | | ASN1_Type type_tag = ASN1_Type::Sequence, |
291 | | ASN1_Class class_tag = ASN1_Class::Universal); |
292 | | |
293 | | template<typename T> |
294 | | BER_Decoder& decode_and_check(const T& expected, |
295 | | const std::string& error_msg) |
296 | 7.65k | { |
297 | 7.65k | T actual; |
298 | 7.65k | decode(actual); |
299 | | |
300 | 7.65k | if(actual != expected) |
301 | 311 | throw Decoding_Error(error_msg); |
302 | | |
303 | 7.34k | return (*this); |
304 | 7.34k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_and_check<unsigned long>(unsigned long const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 296 | 4.66k | { | 297 | 4.66k | T actual; | 298 | 4.66k | decode(actual); | 299 | | | 300 | 4.66k | if(actual != expected) | 301 | 158 | throw Decoding_Error(error_msg); | 302 | | | 303 | 4.50k | return (*this); | 304 | 4.50k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_and_check<Botan::OID>(Botan::OID const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 296 | 2.98k | { | 297 | 2.98k | T actual; | 298 | 2.98k | decode(actual); | 299 | | | 300 | 2.98k | if(actual != expected) | 301 | 153 | throw Decoding_Error(error_msg); | 302 | | | 303 | 2.83k | return (*this); | 304 | 2.83k | } |
|
305 | | |
306 | | /* |
307 | | * Decode an OPTIONAL string type |
308 | | */ |
309 | | template<typename Alloc> |
310 | | BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out, |
311 | | ASN1_Type real_type, |
312 | | uint32_t expected_tag, |
313 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific) |
314 | 30.2k | { |
315 | 30.2k | BER_Object obj = get_next_object(); |
316 | | |
317 | 30.2k | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); |
318 | | |
319 | 30.2k | if(obj.is_a(type_tag, class_tag)) |
320 | 1.49k | { |
321 | 1.49k | if(class_tag == ASN1_Class::ExplicitContextSpecific) |
322 | 918 | { |
323 | 918 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); |
324 | 918 | } |
325 | 573 | else |
326 | 573 | { |
327 | 573 | push_back(std::move(obj)); |
328 | 573 | decode(out, real_type, type_tag, class_tag); |
329 | 573 | } |
330 | 1.49k | } |
331 | 28.7k | else |
332 | 28.7k | { |
333 | 28.7k | out.clear(); |
334 | 28.7k | push_back(std::move(obj)); |
335 | 28.7k | } |
336 | | |
337 | 30.2k | return (*this); |
338 | 30.2k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_optional_string<std::__1::allocator<unsigned char> >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, Botan::ASN1_Type, unsigned int, Botan::ASN1_Class) Line | Count | Source | 314 | 29.1k | { | 315 | 29.1k | BER_Object obj = get_next_object(); | 316 | | | 317 | 29.1k | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); | 318 | | | 319 | 29.1k | if(obj.is_a(type_tag, class_tag)) | 320 | 759 | { | 321 | 759 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 322 | 186 | { | 323 | 186 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 324 | 186 | } | 325 | 573 | else | 326 | 573 | { | 327 | 573 | push_back(std::move(obj)); | 328 | 573 | decode(out, real_type, type_tag, class_tag); | 329 | 573 | } | 330 | 759 | } | 331 | 28.4k | else | 332 | 28.4k | { | 333 | 28.4k | out.clear(); | 334 | 28.4k | push_back(std::move(obj)); | 335 | 28.4k | } | 336 | | | 337 | 29.1k | return (*this); | 338 | 29.1k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional_string<Botan::secure_allocator<unsigned char> >(std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> >&, Botan::ASN1_Type, unsigned int, Botan::ASN1_Class) Line | Count | Source | 314 | 1.09k | { | 315 | 1.09k | BER_Object obj = get_next_object(); | 316 | | | 317 | 1.09k | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); | 318 | | | 319 | 1.09k | if(obj.is_a(type_tag, class_tag)) | 320 | 732 | { | 321 | 732 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 322 | 732 | { | 323 | 732 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 324 | 732 | } | 325 | 0 | else | 326 | 0 | { | 327 | 0 | push_back(std::move(obj)); | 328 | 0 | decode(out, real_type, type_tag, class_tag); | 329 | 0 | } | 330 | 732 | } | 331 | 364 | else | 332 | 364 | { | 333 | 364 | out.clear(); | 334 | 364 | push_back(std::move(obj)); | 335 | 364 | } | 336 | | | 337 | 1.09k | return (*this); | 338 | 1.09k | } |
|
339 | | |
340 | | template<typename Alloc> |
341 | | BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out, |
342 | | ASN1_Type real_type, |
343 | | ASN1_Type expected_tag, |
344 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific) |
345 | 392 | { |
346 | 392 | return decode_optional_string(out, real_type, |
347 | 392 | static_cast<uint32_t>(expected_tag), |
348 | 392 | class_tag); |
349 | 392 | } |
350 | | |
351 | | private: |
352 | | BER_Decoder(BER_Object&& obj, BER_Decoder* parent); |
353 | | |
354 | | BER_Decoder* m_parent = nullptr; |
355 | | BER_Object m_pushed; |
356 | | // either m_data_src.get() or an unowned pointer |
357 | | DataSource* m_source; |
358 | | mutable std::unique_ptr<DataSource> m_data_src; |
359 | | }; |
360 | | |
361 | | /* |
362 | | * Decode an OPTIONAL or DEFAULT element |
363 | | */ |
364 | | template<typename T> |
365 | | BER_Decoder& BER_Decoder::decode_optional(T& out, |
366 | | ASN1_Type type_tag, |
367 | | ASN1_Class class_tag, |
368 | | const T& default_value) |
369 | 74.6k | { |
370 | 74.6k | BER_Object obj = get_next_object(); |
371 | | |
372 | 74.6k | if(obj.is_a(type_tag, class_tag)) |
373 | 12.9k | { |
374 | 12.9k | if(class_tag == ASN1_Class::ExplicitContextSpecific) |
375 | 7.89k | { |
376 | 7.89k | BER_Decoder(std::move(obj)).decode(out).verify_end(); |
377 | 7.89k | } |
378 | 5.10k | else |
379 | 5.10k | { |
380 | 5.10k | push_back(std::move(obj)); |
381 | 5.10k | decode(out, type_tag, class_tag); |
382 | 5.10k | } |
383 | 12.9k | } |
384 | 61.6k | else |
385 | 61.6k | { |
386 | 61.6k | out = default_value; |
387 | 61.6k | push_back(std::move(obj)); |
388 | 61.6k | } |
389 | | |
390 | 74.6k | return (*this); |
391 | 74.6k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<unsigned long>(unsigned long&, Botan::ASN1_Type, Botan::ASN1_Class, unsigned long const&) Line | Count | Source | 369 | 23.7k | { | 370 | 23.7k | BER_Object obj = get_next_object(); | 371 | | | 372 | 23.7k | if(obj.is_a(type_tag, class_tag)) | 373 | 8.30k | { | 374 | 8.30k | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 6.86k | { | 376 | 6.86k | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 6.86k | } | 378 | 1.44k | else | 379 | 1.44k | { | 380 | 1.44k | push_back(std::move(obj)); | 381 | 1.44k | decode(out, type_tag, class_tag); | 382 | 1.44k | } | 383 | 8.30k | } | 384 | 15.4k | else | 385 | 15.4k | { | 386 | 15.4k | out = default_value; | 387 | 15.4k | push_back(std::move(obj)); | 388 | 15.4k | } | 389 | | | 390 | 23.7k | return (*this); | 391 | 23.7k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::X509_DN>(Botan::X509_DN&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::X509_DN const&) Line | Count | Source | 369 | 1.57k | { | 370 | 1.57k | BER_Object obj = get_next_object(); | 371 | | | 372 | 1.57k | if(obj.is_a(type_tag, class_tag)) | 373 | 264 | { | 374 | 264 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 264 | { | 376 | 264 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 264 | } | 378 | 0 | else | 379 | 0 | { | 380 | 0 | push_back(std::move(obj)); | 381 | 0 | decode(out, type_tag, class_tag); | 382 | 0 | } | 383 | 264 | } | 384 | 1.30k | else | 385 | 1.30k | { | 386 | 1.30k | out = default_value; | 387 | 1.30k | push_back(std::move(obj)); | 388 | 1.30k | } | 389 | | | 390 | 1.57k | return (*this); | 391 | 1.57k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::Extensions>(Botan::Extensions&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::Extensions const&) Line | Count | Source | 369 | 621 | { | 370 | 621 | BER_Object obj = get_next_object(); | 371 | | | 372 | 621 | if(obj.is_a(type_tag, class_tag)) | 373 | 599 | { | 374 | 599 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 599 | { | 376 | 599 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 599 | } | 378 | 0 | else | 379 | 0 | { | 380 | 0 | push_back(std::move(obj)); | 381 | 0 | decode(out, type_tag, class_tag); | 382 | 0 | } | 383 | 599 | } | 384 | 22 | else | 385 | 22 | { | 386 | 22 | out = default_value; | 387 | 22 | push_back(std::move(obj)); | 388 | 22 | } | 389 | | | 390 | 621 | return (*this); | 391 | 621 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::ASN1_Time>(Botan::ASN1_Time&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::ASN1_Time const&) Line | Count | Source | 369 | 14 | { | 370 | 14 | BER_Object obj = get_next_object(); | 371 | | | 372 | 14 | if(obj.is_a(type_tag, class_tag)) | 373 | 6 | { | 374 | 6 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 6 | { | 376 | 6 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 6 | } | 378 | 0 | else | 379 | 0 | { | 380 | 0 | push_back(std::move(obj)); | 381 | 0 | decode(out, type_tag, class_tag); | 382 | 0 | } | 383 | 6 | } | 384 | 8 | else | 385 | 8 | { | 386 | 8 | out = default_value; | 387 | 8 | push_back(std::move(obj)); | 388 | 8 | } | 389 | | | 390 | 14 | return (*this); | 391 | 14 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<bool>(bool&, Botan::ASN1_Type, Botan::ASN1_Class, bool const&) Line | Count | Source | 369 | 47.4k | { | 370 | 47.4k | BER_Object obj = get_next_object(); | 371 | | | 372 | 47.4k | if(obj.is_a(type_tag, class_tag)) | 373 | 3.65k | { | 374 | 3.65k | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 0 | { | 376 | 0 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 0 | } | 378 | 3.65k | else | 379 | 3.65k | { | 380 | 3.65k | push_back(std::move(obj)); | 381 | 3.65k | decode(out, type_tag, class_tag); | 382 | 3.65k | } | 383 | 3.65k | } | 384 | 43.7k | else | 385 | 43.7k | { | 386 | 43.7k | out = default_value; | 387 | 43.7k | push_back(std::move(obj)); | 388 | 43.7k | } | 389 | | | 390 | 47.4k | return (*this); | 391 | 47.4k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::AlgorithmIdentifier>(Botan::AlgorithmIdentifier&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::AlgorithmIdentifier const&) Line | Count | Source | 369 | 145 | { | 370 | 145 | BER_Object obj = get_next_object(); | 371 | | | 372 | 145 | if(obj.is_a(type_tag, class_tag)) | 373 | 142 | { | 374 | 142 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 142 | { | 376 | 142 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 142 | } | 378 | 0 | else | 379 | 0 | { | 380 | 0 | push_back(std::move(obj)); | 381 | 0 | decode(out, type_tag, class_tag); | 382 | 0 | } | 383 | 142 | } | 384 | 3 | else | 385 | 3 | { | 386 | 3 | out = default_value; | 387 | 3 | push_back(std::move(obj)); | 388 | 3 | } | 389 | | | 390 | 145 | return (*this); | 391 | 145 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::OID>(Botan::OID&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::OID const&) Line | Count | Source | 369 | 1.10k | { | 370 | 1.10k | BER_Object obj = get_next_object(); | 371 | | | 372 | 1.10k | if(obj.is_a(type_tag, class_tag)) | 373 | 21 | { | 374 | 21 | if(class_tag == ASN1_Class::ExplicitContextSpecific) | 375 | 21 | { | 376 | 21 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 377 | 21 | } | 378 | 0 | else | 379 | 0 | { | 380 | 0 | push_back(std::move(obj)); | 381 | 0 | decode(out, type_tag, class_tag); | 382 | 0 | } | 383 | 21 | } | 384 | 1.08k | else | 385 | 1.08k | { | 386 | 1.08k | out = default_value; | 387 | 1.08k | push_back(std::move(obj)); | 388 | 1.08k | } | 389 | | | 390 | 1.10k | return (*this); | 391 | 1.10k | } |
|
392 | | |
393 | | /* |
394 | | * Decode an OPTIONAL or DEFAULT element |
395 | | */ |
396 | | template<typename T> |
397 | | BER_Decoder& BER_Decoder::decode_optional_implicit( |
398 | | T& out, |
399 | | ASN1_Type type_tag, |
400 | | ASN1_Class class_tag, |
401 | | ASN1_Type real_type, |
402 | | ASN1_Class real_class, |
403 | | const T& default_value) |
404 | 3.00k | { |
405 | 3.00k | BER_Object obj = get_next_object(); |
406 | | |
407 | 3.00k | if(obj.is_a(type_tag, class_tag)) |
408 | 766 | { |
409 | 766 | obj.set_tagging(real_type, real_class); |
410 | 766 | push_back(std::move(obj)); |
411 | 766 | decode(out, real_type, real_class); |
412 | 766 | } |
413 | 2.23k | else |
414 | 2.23k | { |
415 | | // Not what we wanted, push it back on the stream |
416 | 2.23k | out = default_value; |
417 | 2.23k | push_back(std::move(obj)); |
418 | 2.23k | } |
419 | | |
420 | 3.00k | return (*this); |
421 | 3.00k | } |
422 | | /* |
423 | | * Decode a list of homogenously typed values |
424 | | */ |
425 | | template<typename T> |
426 | | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, |
427 | | ASN1_Type type_tag, |
428 | | ASN1_Class class_tag) |
429 | 9.32k | { |
430 | 9.32k | BER_Decoder list = start_cons(type_tag, class_tag); |
431 | | |
432 | 22.2k | while(list.more_items()) |
433 | 12.8k | { |
434 | 12.8k | T value; |
435 | 12.8k | list.decode(value); |
436 | 12.8k | vec.push_back(std::move(value)); |
437 | 12.8k | } |
438 | | |
439 | 9.32k | list.end_cons(); |
440 | | |
441 | 9.32k | return (*this); |
442 | 9.32k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::OCSP::SingleResponse>(std::__1::vector<Botan::OCSP::SingleResponse, std::__1::allocator<Botan::OCSP::SingleResponse> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 429 | 646 | { | 430 | 646 | BER_Decoder list = start_cons(type_tag, class_tag); | 431 | | | 432 | 680 | while(list.more_items()) | 433 | 34 | { | 434 | 34 | T value; | 435 | 34 | list.decode(value); | 436 | 34 | vec.push_back(std::move(value)); | 437 | 34 | } | 438 | | | 439 | 646 | list.end_cons(); | 440 | | | 441 | 646 | return (*this); | 442 | 646 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::OID>(std::__1::vector<Botan::OID, std::__1::allocator<Botan::OID> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 429 | 2.39k | { | 430 | 2.39k | BER_Decoder list = start_cons(type_tag, class_tag); | 431 | | | 432 | 4.07k | while(list.more_items()) | 433 | 1.67k | { | 434 | 1.67k | T value; | 435 | 1.67k | list.decode(value); | 436 | 1.67k | vec.push_back(std::move(value)); | 437 | 1.67k | } | 438 | | | 439 | 2.39k | list.end_cons(); | 440 | | | 441 | 2.39k | return (*this); | 442 | 2.39k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::GeneralSubtree>(std::__1::vector<Botan::GeneralSubtree, std::__1::allocator<Botan::GeneralSubtree> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 429 | 3.26k | { | 430 | 3.26k | BER_Decoder list = start_cons(type_tag, class_tag); | 431 | | | 432 | 9.52k | while(list.more_items()) | 433 | 6.25k | { | 434 | 6.25k | T value; | 435 | 6.25k | list.decode(value); | 436 | 6.25k | vec.push_back(std::move(value)); | 437 | 6.25k | } | 438 | | | 439 | 3.26k | list.end_cons(); | 440 | | | 441 | 3.26k | return (*this); | 442 | 3.26k | } |
x509_ext.cpp:Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::Cert_Extension::(anonymous namespace)::Policy_Information>(std::__1::vector<Botan::Cert_Extension::(anonymous namespace)::Policy_Information, std::__1::allocator<Botan::Cert_Extension::(anonymous namespace)::Policy_Information> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 429 | 997 | { | 430 | 997 | BER_Decoder list = start_cons(type_tag, class_tag); | 431 | | | 432 | 2.42k | while(list.more_items()) | 433 | 1.42k | { | 434 | 1.42k | T value; | 435 | 1.42k | list.decode(value); | 436 | 1.42k | vec.push_back(std::move(value)); | 437 | 1.42k | } | 438 | | | 439 | 997 | list.end_cons(); | 440 | | | 441 | 997 | return (*this); | 442 | 997 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point>(std::__1::vector<Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point, std::__1::allocator<Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 429 | 2.03k | { | 430 | 2.03k | BER_Decoder list = start_cons(type_tag, class_tag); | 431 | | | 432 | 5.52k | while(list.more_items()) | 433 | 3.49k | { | 434 | 3.49k | T value; | 435 | 3.49k | list.decode(value); | 436 | 3.49k | vec.push_back(std::move(value)); | 437 | 3.49k | } | 438 | | | 439 | 2.03k | list.end_cons(); | 440 | | | 441 | 2.03k | return (*this); | 442 | 2.03k | } |
|
443 | | |
444 | | } |
445 | | |
446 | | #endif |