/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 | 27.5k | 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.6k | 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.1k | { |
68 | 26.1k | ber = get_next_object(); |
69 | 26.1k | return (*this); |
70 | 26.1k | } |
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 | | /** |
110 | | * Start decoding a constructed data (sequence or set) |
111 | | */ |
112 | | BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag = UNIVERSAL); |
113 | | |
114 | | /** |
115 | | * Finish decoding a constructed data, throws if any data remains. |
116 | | * Returns the parent of *this (ie the object on which start_cons was called). |
117 | | */ |
118 | | BER_Decoder& end_cons(); |
119 | | |
120 | | /** |
121 | | * Get next object and copy value to POD type |
122 | | * Asserts value length is equal to POD type sizeof. |
123 | | * Asserts Type tag and optional Class tag according to parameters. |
124 | | * Copy value to POD type (struct, union, C-style array, std::array, etc.). |
125 | | * @param out POD type reference where to copy object value |
126 | | * @param type_tag ASN1_Tag enum to assert type on object read |
127 | | * @param class_tag ASN1_Tag enum to assert class on object read (default: CONTEXT_SPECIFIC) |
128 | | * @return this reference |
129 | | */ |
130 | | template <typename T> |
131 | | BER_Decoder& get_next_value(T &out, |
132 | | ASN1_Tag type_tag, |
133 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC) |
134 | | { |
135 | | static_assert(std::is_pod<T>::value, "Type must be POD"); |
136 | | |
137 | | BER_Object obj = get_next_object(); |
138 | | obj.assert_is_a(type_tag, class_tag); |
139 | | |
140 | | if (obj.length() != sizeof(T)) |
141 | | throw BER_Decoding_Error( |
142 | | "Size mismatch. Object value size is " + |
143 | | std::to_string(obj.length()) + |
144 | | "; Output type size is " + |
145 | | std::to_string(sizeof(T))); |
146 | | |
147 | | copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length()); |
148 | | |
149 | | return (*this); |
150 | | } |
151 | | |
152 | | /* |
153 | | * Save all the bytes remaining in the source |
154 | | */ |
155 | | template<typename Alloc> |
156 | | BER_Decoder& raw_bytes(std::vector<uint8_t, Alloc>& out) |
157 | 130k | { |
158 | 130k | out.clear(); |
159 | 130k | uint8_t buf; |
160 | 12.1M | while(m_source->read_byte(buf)) |
161 | 11.9M | out.push_back(buf); |
162 | 130k | return (*this); |
163 | 130k | } |
164 | | |
165 | | BER_Decoder& decode_null(); |
166 | | |
167 | | /** |
168 | | * Decode a BER encoded BOOLEAN |
169 | | */ |
170 | | BER_Decoder& decode(bool& out) |
171 | 1.55k | { |
172 | 1.55k | return decode(out, BOOLEAN, UNIVERSAL); |
173 | 1.55k | } |
174 | | |
175 | | /* |
176 | | * Decode a small BER encoded INTEGER |
177 | | */ |
178 | | BER_Decoder& decode(size_t& out) |
179 | 11.7k | { |
180 | 11.7k | return decode(out, INTEGER, UNIVERSAL); |
181 | 11.7k | } |
182 | | |
183 | | /* |
184 | | * Decode a BER encoded INTEGER |
185 | | */ |
186 | | BER_Decoder& decode(BigInt& out) |
187 | 47.6k | { |
188 | 47.6k | return decode(out, INTEGER, UNIVERSAL); |
189 | 47.6k | } |
190 | | |
191 | | std::vector<uint8_t> get_next_octet_string() |
192 | 2.63k | { |
193 | 2.63k | std::vector<uint8_t> out_vec; |
194 | 2.63k | decode(out_vec, OCTET_STRING); |
195 | 2.63k | return out_vec; |
196 | 2.63k | } |
197 | | |
198 | | /* |
199 | | * BER decode a BIT STRING or OCTET STRING |
200 | | */ |
201 | | template<typename Alloc> |
202 | | BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Tag real_type) |
203 | 107k | { |
204 | 107k | return decode(out, real_type, real_type, UNIVERSAL); |
205 | 107k | } Botan::BER_Decoder& Botan::BER_Decoder::decode<Botan::secure_allocator<unsigned char> >(std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> >&, Botan::ASN1_Tag) Line | Count | Source | 203 | 4.69k | { | 204 | 4.69k | return decode(out, real_type, real_type, UNIVERSAL); | 205 | 4.69k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode<std::__1::allocator<unsigned char> >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, Botan::ASN1_Tag) Line | Count | Source | 203 | 103k | { | 204 | 103k | return decode(out, real_type, real_type, UNIVERSAL); | 205 | 103k | } |
|
206 | | |
207 | | BER_Decoder& decode(bool& v, |
208 | | ASN1_Tag type_tag, |
209 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC); |
210 | | |
211 | | BER_Decoder& decode(size_t& v, |
212 | | ASN1_Tag type_tag, |
213 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC); |
214 | | |
215 | | BER_Decoder& decode(BigInt& v, |
216 | | ASN1_Tag type_tag, |
217 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC); |
218 | | |
219 | | BER_Decoder& decode(std::vector<uint8_t>& v, |
220 | | ASN1_Tag real_type, |
221 | | ASN1_Tag type_tag, |
222 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC); |
223 | | |
224 | | BER_Decoder& decode(secure_vector<uint8_t>& v, |
225 | | ASN1_Tag real_type, |
226 | | ASN1_Tag type_tag, |
227 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC); |
228 | | |
229 | | BER_Decoder& decode(class ASN1_Object& obj, |
230 | | ASN1_Tag type_tag = NO_OBJECT, |
231 | | ASN1_Tag class_tag = NO_OBJECT); |
232 | | |
233 | | /** |
234 | | * Decode an integer value which is typed as an octet string |
235 | | */ |
236 | | BER_Decoder& decode_octet_string_bigint(BigInt& b); |
237 | | |
238 | | uint64_t decode_constrained_integer(ASN1_Tag type_tag, |
239 | | ASN1_Tag class_tag, |
240 | | size_t T_bytes); |
241 | | |
242 | | template<typename T> BER_Decoder& decode_integer_type(T& out) |
243 | 0 | { |
244 | 0 | return decode_integer_type<T>(out, INTEGER, UNIVERSAL); |
245 | 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&) |
246 | | |
247 | | template<typename T> |
248 | | BER_Decoder& decode_integer_type(T& out, |
249 | | ASN1_Tag type_tag, |
250 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC) |
251 | 0 | { |
252 | 0 | out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out))); |
253 | 0 | return (*this); |
254 | 0 | } Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned long>(unsigned long&, Botan::ASN1_Tag, Botan::ASN1_Tag) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned char>(unsigned char&, Botan::ASN1_Tag, Botan::ASN1_Tag) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned short>(unsigned short&, Botan::ASN1_Tag, Botan::ASN1_Tag) |
255 | | |
256 | | template<typename T> |
257 | | BER_Decoder& decode_optional(T& out, |
258 | | ASN1_Tag type_tag, |
259 | | ASN1_Tag class_tag, |
260 | | const T& default_value = T()); |
261 | | |
262 | | template<typename T> |
263 | | BER_Decoder& decode_optional_implicit( |
264 | | T& out, |
265 | | ASN1_Tag type_tag, |
266 | | ASN1_Tag class_tag, |
267 | | ASN1_Tag real_type, |
268 | | ASN1_Tag real_class, |
269 | | const T& default_value = T()); |
270 | | |
271 | | template<typename T> |
272 | | BER_Decoder& decode_list(std::vector<T>& out, |
273 | | ASN1_Tag type_tag = SEQUENCE, |
274 | | ASN1_Tag class_tag = UNIVERSAL); |
275 | | |
276 | | template<typename T> |
277 | | BER_Decoder& decode_and_check(const T& expected, |
278 | | const std::string& error_msg) |
279 | 7.70k | { |
280 | 7.70k | T actual; |
281 | 7.70k | decode(actual); |
282 | 7.70k | |
283 | 7.70k | if(actual != expected) |
284 | 320 | throw Decoding_Error(error_msg); |
285 | 7.38k | |
286 | 7.38k | return (*this); |
287 | 7.38k | } 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 | 279 | 4.40k | { | 280 | 4.40k | T actual; | 281 | 4.40k | decode(actual); | 282 | 4.40k | | 283 | 4.40k | if(actual != expected) | 284 | 133 | throw Decoding_Error(error_msg); | 285 | 4.27k | | 286 | 4.27k | return (*this); | 287 | 4.27k | } |
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 | 279 | 3.29k | { | 280 | 3.29k | T actual; | 281 | 3.29k | decode(actual); | 282 | 3.29k | | 283 | 3.29k | if(actual != expected) | 284 | 187 | throw Decoding_Error(error_msg); | 285 | 3.11k | | 286 | 3.11k | return (*this); | 287 | 3.11k | } |
|
288 | | |
289 | | /* |
290 | | * Decode an OPTIONAL string type |
291 | | */ |
292 | | template<typename Alloc> |
293 | | BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out, |
294 | | ASN1_Tag real_type, |
295 | | uint16_t type_no, |
296 | | ASN1_Tag class_tag = CONTEXT_SPECIFIC) |
297 | 30.1k | { |
298 | 30.1k | BER_Object obj = get_next_object(); |
299 | 30.1k | |
300 | 30.1k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); |
301 | 30.1k | |
302 | 30.1k | if(obj.is_a(type_tag, class_tag)) |
303 | 1.73k | { |
304 | 1.73k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) |
305 | 1.03k | { |
306 | 1.03k | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); |
307 | 1.03k | } |
308 | 693 | else |
309 | 693 | { |
310 | 693 | push_back(std::move(obj)); |
311 | 693 | decode(out, real_type, type_tag, class_tag); |
312 | 693 | } |
313 | 1.73k | } |
314 | 28.4k | else |
315 | 28.4k | { |
316 | 28.4k | out.clear(); |
317 | 28.4k | push_back(std::move(obj)); |
318 | 28.4k | } |
319 | 30.1k | |
320 | 30.1k | return (*this); |
321 | 30.1k | } 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_Tag, unsigned short, Botan::ASN1_Tag) Line | Count | Source | 297 | 29.0k | { | 298 | 29.0k | BER_Object obj = get_next_object(); | 299 | 29.0k | | 300 | 29.0k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); | 301 | 29.0k | | 302 | 29.0k | if(obj.is_a(type_tag, class_tag)) | 303 | 1.00k | { | 304 | 1.00k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 305 | 314 | { | 306 | 314 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 307 | 314 | } | 308 | 693 | else | 309 | 693 | { | 310 | 693 | push_back(std::move(obj)); | 311 | 693 | decode(out, real_type, type_tag, class_tag); | 312 | 693 | } | 313 | 1.00k | } | 314 | 28.0k | else | 315 | 28.0k | { | 316 | 28.0k | out.clear(); | 317 | 28.0k | push_back(std::move(obj)); | 318 | 28.0k | } | 319 | 29.0k | | 320 | 29.0k | return (*this); | 321 | 29.0k | } |
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_Tag, unsigned short, Botan::ASN1_Tag) Line | Count | Source | 297 | 1.10k | { | 298 | 1.10k | BER_Object obj = get_next_object(); | 299 | 1.10k | | 300 | 1.10k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); | 301 | 1.10k | | 302 | 1.10k | if(obj.is_a(type_tag, class_tag)) | 303 | 723 | { | 304 | 723 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 305 | 723 | { | 306 | 723 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 307 | 723 | } | 308 | 0 | else | 309 | 0 | { | 310 | 0 | push_back(std::move(obj)); | 311 | 0 | decode(out, real_type, type_tag, class_tag); | 312 | 0 | } | 313 | 723 | } | 314 | 382 | else | 315 | 382 | { | 316 | 382 | out.clear(); | 317 | 382 | push_back(std::move(obj)); | 318 | 382 | } | 319 | 1.10k | | 320 | 1.10k | return (*this); | 321 | 1.10k | } |
|
322 | | |
323 | | private: |
324 | | BER_Decoder(BER_Object&& obj, BER_Decoder* parent); |
325 | | |
326 | | BER_Decoder* m_parent = nullptr; |
327 | | BER_Object m_pushed; |
328 | | // either m_data_src.get() or an unowned pointer |
329 | | DataSource* m_source; |
330 | | mutable std::unique_ptr<DataSource> m_data_src; |
331 | | }; |
332 | | |
333 | | /* |
334 | | * Decode an OPTIONAL or DEFAULT element |
335 | | */ |
336 | | template<typename T> |
337 | | BER_Decoder& BER_Decoder::decode_optional(T& out, |
338 | | ASN1_Tag type_tag, |
339 | | ASN1_Tag class_tag, |
340 | | const T& default_value) |
341 | 67.9k | { |
342 | 67.9k | BER_Object obj = get_next_object(); |
343 | 67.9k | |
344 | 67.9k | if(obj.is_a(type_tag, class_tag)) |
345 | 13.4k | { |
346 | 13.4k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) |
347 | 7.87k | { |
348 | 7.87k | BER_Decoder(std::move(obj)).decode(out).verify_end(); |
349 | 7.87k | } |
350 | 5.58k | else |
351 | 5.58k | { |
352 | 5.58k | push_back(std::move(obj)); |
353 | 5.58k | decode(out, type_tag, class_tag); |
354 | 5.58k | } |
355 | 13.4k | } |
356 | 54.5k | else |
357 | 54.5k | { |
358 | 54.5k | out = default_value; |
359 | 54.5k | push_back(std::move(obj)); |
360 | 54.5k | } |
361 | 67.9k | |
362 | 67.9k | return (*this); |
363 | 67.9k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::AlgorithmIdentifier>(Botan::AlgorithmIdentifier&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::AlgorithmIdentifier const&) Line | Count | Source | 341 | 139 | { | 342 | 139 | BER_Object obj = get_next_object(); | 343 | 139 | | 344 | 139 | if(obj.is_a(type_tag, class_tag)) | 345 | 137 | { | 346 | 137 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 137 | { | 348 | 137 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 137 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 137 | } | 356 | 2 | else | 357 | 2 | { | 358 | 2 | out = default_value; | 359 | 2 | push_back(std::move(obj)); | 360 | 2 | } | 361 | 139 | | 362 | 139 | return (*this); | 363 | 139 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<unsigned long>(unsigned long&, Botan::ASN1_Tag, Botan::ASN1_Tag, unsigned long const&) Line | Count | Source | 341 | 23.6k | { | 342 | 23.6k | BER_Object obj = get_next_object(); | 343 | 23.6k | | 344 | 23.6k | if(obj.is_a(type_tag, class_tag)) | 345 | 8.07k | { | 346 | 8.07k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 6.70k | { | 348 | 6.70k | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 6.70k | } | 350 | 1.36k | else | 351 | 1.36k | { | 352 | 1.36k | push_back(std::move(obj)); | 353 | 1.36k | decode(out, type_tag, class_tag); | 354 | 1.36k | } | 355 | 8.07k | } | 356 | 15.5k | else | 357 | 15.5k | { | 358 | 15.5k | out = default_value; | 359 | 15.5k | push_back(std::move(obj)); | 360 | 15.5k | } | 361 | 23.6k | | 362 | 23.6k | return (*this); | 363 | 23.6k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::OID>(Botan::OID&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::OID const&) Line | Count | Source | 341 | 1.11k | { | 342 | 1.11k | BER_Object obj = get_next_object(); | 343 | 1.11k | | 344 | 1.11k | if(obj.is_a(type_tag, class_tag)) | 345 | 37 | { | 346 | 37 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 37 | { | 348 | 37 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 37 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 37 | } | 356 | 1.07k | else | 357 | 1.07k | { | 358 | 1.07k | out = default_value; | 359 | 1.07k | push_back(std::move(obj)); | 360 | 1.07k | } | 361 | 1.11k | | 362 | 1.11k | return (*this); | 363 | 1.11k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::X509_DN>(Botan::X509_DN&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::X509_DN const&) Line | Count | Source | 341 | 1.59k | { | 342 | 1.59k | BER_Object obj = get_next_object(); | 343 | 1.59k | | 344 | 1.59k | if(obj.is_a(type_tag, class_tag)) | 345 | 52 | { | 346 | 52 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 52 | { | 348 | 52 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 52 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 52 | } | 356 | 1.54k | else | 357 | 1.54k | { | 358 | 1.54k | out = default_value; | 359 | 1.54k | push_back(std::move(obj)); | 360 | 1.54k | } | 361 | 1.59k | | 362 | 1.59k | return (*this); | 363 | 1.59k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::Extensions>(Botan::Extensions&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::Extensions const&) Line | Count | Source | 341 | 953 | { | 342 | 953 | BER_Object obj = get_next_object(); | 343 | 953 | | 344 | 953 | if(obj.is_a(type_tag, class_tag)) | 345 | 928 | { | 346 | 928 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 928 | { | 348 | 928 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 928 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 928 | } | 356 | 25 | else | 357 | 25 | { | 358 | 25 | out = default_value; | 359 | 25 | push_back(std::move(obj)); | 360 | 25 | } | 361 | 953 | | 362 | 953 | return (*this); | 363 | 953 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::X509_Time>(Botan::X509_Time&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::X509_Time const&) Line | Count | Source | 341 | 28 | { | 342 | 28 | BER_Object obj = get_next_object(); | 343 | 28 | | 344 | 28 | if(obj.is_a(type_tag, class_tag)) | 345 | 17 | { | 346 | 17 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 17 | { | 348 | 17 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 17 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 17 | } | 356 | 11 | else | 357 | 11 | { | 358 | 11 | out = default_value; | 359 | 11 | push_back(std::move(obj)); | 360 | 11 | } | 361 | 28 | | 362 | 28 | return (*this); | 363 | 28 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<bool>(bool&, Botan::ASN1_Tag, Botan::ASN1_Tag, bool const&) Line | Count | Source | 341 | 40.4k | { | 342 | 40.4k | BER_Object obj = get_next_object(); | 343 | 40.4k | | 344 | 40.4k | if(obj.is_a(type_tag, class_tag)) | 345 | 4.21k | { | 346 | 4.21k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 0 | { | 348 | 0 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 0 | } | 350 | 4.21k | else | 351 | 4.21k | { | 352 | 4.21k | push_back(std::move(obj)); | 353 | 4.21k | decode(out, type_tag, class_tag); | 354 | 4.21k | } | 355 | 4.21k | } | 356 | 36.2k | else | 357 | 36.2k | { | 358 | 36.2k | out = default_value; | 359 | 36.2k | push_back(std::move(obj)); | 360 | 36.2k | } | 361 | 40.4k | | 362 | 40.4k | return (*this); | 363 | 40.4k | } |
|
364 | | |
365 | | /* |
366 | | * Decode an OPTIONAL or DEFAULT element |
367 | | */ |
368 | | template<typename T> |
369 | | BER_Decoder& BER_Decoder::decode_optional_implicit( |
370 | | T& out, |
371 | | ASN1_Tag type_tag, |
372 | | ASN1_Tag class_tag, |
373 | | ASN1_Tag real_type, |
374 | | ASN1_Tag real_class, |
375 | | const T& default_value) |
376 | 1.11k | { |
377 | 1.11k | BER_Object obj = get_next_object(); |
378 | 1.11k | |
379 | 1.11k | if(obj.is_a(type_tag, class_tag)) |
380 | 712 | { |
381 | 712 | obj.set_tagging(real_type, real_class); |
382 | 712 | push_back(std::move(obj)); |
383 | 712 | decode(out, real_type, real_class); |
384 | 712 | } |
385 | 399 | else |
386 | 399 | { |
387 | | // Not what we wanted, push it back on the stream |
388 | 399 | out = default_value; |
389 | 399 | push_back(std::move(obj)); |
390 | 399 | } |
391 | 1.11k | |
392 | 1.11k | return (*this); |
393 | 1.11k | } |
394 | | /* |
395 | | * Decode a list of homogenously typed values |
396 | | */ |
397 | | template<typename T> |
398 | | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, |
399 | | ASN1_Tag type_tag, |
400 | | ASN1_Tag class_tag) |
401 | 7.67k | { |
402 | 7.67k | BER_Decoder list = start_cons(type_tag, class_tag); |
403 | 7.67k | |
404 | 17.8k | while(list.more_items()) |
405 | 10.2k | { |
406 | 10.2k | T value; |
407 | 10.2k | list.decode(value); |
408 | 10.2k | vec.push_back(std::move(value)); |
409 | 10.2k | } |
410 | 7.67k | |
411 | 7.67k | list.end_cons(); |
412 | 7.67k | |
413 | 7.67k | return (*this); |
414 | 7.67k | } 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_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 990 | { | 402 | 990 | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 990 | | 404 | 1.03k | while(list.more_items()) | 405 | 44 | { | 406 | 44 | T value; | 407 | 44 | list.decode(value); | 408 | 44 | vec.push_back(std::move(value)); | 409 | 44 | } | 410 | 990 | | 411 | 990 | list.end_cons(); | 412 | 990 | | 413 | 990 | return (*this); | 414 | 990 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::OID>(std::__1::vector<Botan::OID, std::__1::allocator<Botan::OID> >&, Botan::ASN1_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 1.06k | { | 402 | 1.06k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 1.06k | | 404 | 2.72k | while(list.more_items()) | 405 | 1.65k | { | 406 | 1.65k | T value; | 407 | 1.65k | list.decode(value); | 408 | 1.65k | vec.push_back(std::move(value)); | 409 | 1.65k | } | 410 | 1.06k | | 411 | 1.06k | list.end_cons(); | 412 | 1.06k | | 413 | 1.06k | return (*this); | 414 | 1.06k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::GeneralSubtree>(std::__1::vector<Botan::GeneralSubtree, std::__1::allocator<Botan::GeneralSubtree> >&, Botan::ASN1_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 2.98k | { | 402 | 2.98k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 2.98k | | 404 | 8.98k | while(list.more_items()) | 405 | 6.00k | { | 406 | 6.00k | T value; | 407 | 6.00k | list.decode(value); | 408 | 6.00k | vec.push_back(std::move(value)); | 409 | 6.00k | } | 410 | 2.98k | | 411 | 2.98k | list.end_cons(); | 412 | 2.98k | | 413 | 2.98k | return (*this); | 414 | 2.98k | } |
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_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 1.02k | { | 402 | 1.02k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 1.02k | | 404 | 2.27k | while(list.more_items()) | 405 | 1.24k | { | 406 | 1.24k | T value; | 407 | 1.24k | list.decode(value); | 408 | 1.24k | vec.push_back(std::move(value)); | 409 | 1.24k | } | 410 | 1.02k | | 411 | 1.02k | list.end_cons(); | 412 | 1.02k | | 413 | 1.02k | return (*this); | 414 | 1.02k | } |
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_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 1.61k | { | 402 | 1.61k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 1.61k | | 404 | 2.86k | while(list.more_items()) | 405 | 1.24k | { | 406 | 1.24k | T value; | 407 | 1.24k | list.decode(value); | 408 | 1.24k | vec.push_back(std::move(value)); | 409 | 1.24k | } | 410 | 1.61k | | 411 | 1.61k | list.end_cons(); | 412 | 1.61k | | 413 | 1.61k | return (*this); | 414 | 1.61k | } |
|
415 | | |
416 | | } |
417 | | |
418 | | #endif |