/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.8k | 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.9k | 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.8k | { |
68 | 26.8k | ber = get_next_object(); |
69 | 26.8k | return (*this); |
70 | 26.8k | } |
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 | 131k | { |
158 | 131k | out.clear(); |
159 | 131k | uint8_t buf; |
160 | 12.1M | while(m_source->read_byte(buf)) |
161 | 12.0M | out.push_back(buf); |
162 | 131k | return (*this); |
163 | 131k | } |
164 | | |
165 | | BER_Decoder& decode_null(); |
166 | | |
167 | | /** |
168 | | * Decode a BER encoded BOOLEAN |
169 | | */ |
170 | | BER_Decoder& decode(bool& out) |
171 | 616 | { |
172 | 616 | return decode(out, BOOLEAN, UNIVERSAL); |
173 | 616 | } |
174 | | |
175 | | /* |
176 | | * Decode a small BER encoded INTEGER |
177 | | */ |
178 | | BER_Decoder& decode(size_t& out) |
179 | 12.2k | { |
180 | 12.2k | return decode(out, INTEGER, UNIVERSAL); |
181 | 12.2k | } |
182 | | |
183 | | /* |
184 | | * Decode a BER encoded INTEGER |
185 | | */ |
186 | | BER_Decoder& decode(BigInt& out) |
187 | 49.2k | { |
188 | 49.2k | return decode(out, INTEGER, UNIVERSAL); |
189 | 49.2k | } |
190 | | |
191 | | std::vector<uint8_t> get_next_octet_string() |
192 | 2.53k | { |
193 | 2.53k | std::vector<uint8_t> out_vec; |
194 | 2.53k | decode(out_vec, OCTET_STRING); |
195 | 2.53k | return out_vec; |
196 | 2.53k | } |
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 | 110k | { |
204 | 110k | return decode(out, real_type, real_type, UNIVERSAL); |
205 | 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_Tag) Line | Count | Source | 203 | 4.51k | { | 204 | 4.51k | return decode(out, real_type, real_type, UNIVERSAL); | 205 | 4.51k | } |
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 | 106k | { | 204 | 106k | return decode(out, real_type, real_type, UNIVERSAL); | 205 | 106k | } |
|
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.38k | { |
280 | 7.38k | T actual; |
281 | 7.38k | decode(actual); |
282 | 7.38k | |
283 | 7.38k | if(actual != expected) |
284 | 310 | throw Decoding_Error(error_msg); |
285 | 7.07k | |
286 | 7.07k | return (*this); |
287 | 7.07k | } 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.21k | { | 280 | 4.21k | T actual; | 281 | 4.21k | decode(actual); | 282 | 4.21k | | 283 | 4.21k | if(actual != expected) | 284 | 150 | throw Decoding_Error(error_msg); | 285 | 4.06k | | 286 | 4.06k | return (*this); | 287 | 4.06k | } |
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.16k | { | 280 | 3.16k | T actual; | 281 | 3.16k | decode(actual); | 282 | 3.16k | | 283 | 3.16k | if(actual != expected) | 284 | 160 | throw Decoding_Error(error_msg); | 285 | 3.00k | | 286 | 3.00k | return (*this); | 287 | 3.00k | } |
|
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.5k | { |
298 | 30.5k | BER_Object obj = get_next_object(); |
299 | 30.5k | |
300 | 30.5k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); |
301 | 30.5k | |
302 | 30.5k | if(obj.is_a(type_tag, class_tag)) |
303 | 2.00k | { |
304 | 2.00k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) |
305 | 1.18k | { |
306 | 1.18k | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); |
307 | 1.18k | } |
308 | 821 | else |
309 | 821 | { |
310 | 821 | push_back(std::move(obj)); |
311 | 821 | decode(out, real_type, type_tag, class_tag); |
312 | 821 | } |
313 | 2.00k | } |
314 | 28.5k | else |
315 | 28.5k | { |
316 | 28.5k | out.clear(); |
317 | 28.5k | push_back(std::move(obj)); |
318 | 28.5k | } |
319 | 30.5k | |
320 | 30.5k | return (*this); |
321 | 30.5k | } 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.5k | { | 298 | 29.5k | BER_Object obj = get_next_object(); | 299 | 29.5k | | 300 | 29.5k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); | 301 | 29.5k | | 302 | 29.5k | if(obj.is_a(type_tag, class_tag)) | 303 | 1.32k | { | 304 | 1.32k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 305 | 499 | { | 306 | 499 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 307 | 499 | } | 308 | 821 | else | 309 | 821 | { | 310 | 821 | push_back(std::move(obj)); | 311 | 821 | decode(out, real_type, type_tag, class_tag); | 312 | 821 | } | 313 | 1.32k | } | 314 | 28.2k | else | 315 | 28.2k | { | 316 | 28.2k | out.clear(); | 317 | 28.2k | push_back(std::move(obj)); | 318 | 28.2k | } | 319 | 29.5k | | 320 | 29.5k | return (*this); | 321 | 29.5k | } |
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.04k | { | 298 | 1.04k | BER_Object obj = get_next_object(); | 299 | 1.04k | | 300 | 1.04k | ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no); | 301 | 1.04k | | 302 | 1.04k | if(obj.is_a(type_tag, class_tag)) | 303 | 681 | { | 304 | 681 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 305 | 681 | { | 306 | 681 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 307 | 681 | } | 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 | 681 | } | 314 | 360 | else | 315 | 360 | { | 316 | 360 | out.clear(); | 317 | 360 | push_back(std::move(obj)); | 318 | 360 | } | 319 | 1.04k | | 320 | 1.04k | return (*this); | 321 | 1.04k | } |
|
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 | 68.2k | { |
342 | 68.2k | BER_Object obj = get_next_object(); |
343 | 68.2k | |
344 | 68.2k | if(obj.is_a(type_tag, class_tag)) |
345 | 13.5k | { |
346 | 13.5k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) |
347 | 8.12k | { |
348 | 8.12k | BER_Decoder(std::move(obj)).decode(out).verify_end(); |
349 | 8.12k | } |
350 | 5.44k | else |
351 | 5.44k | { |
352 | 5.44k | push_back(std::move(obj)); |
353 | 5.44k | decode(out, type_tag, class_tag); |
354 | 5.44k | } |
355 | 13.5k | } |
356 | 54.6k | else |
357 | 54.6k | { |
358 | 54.6k | out = default_value; |
359 | 54.6k | push_back(std::move(obj)); |
360 | 54.6k | } |
361 | 68.2k | |
362 | 68.2k | return (*this); |
363 | 68.2k | } 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.5k | { | 342 | 23.5k | BER_Object obj = get_next_object(); | 343 | 23.5k | | 344 | 23.5k | if(obj.is_a(type_tag, class_tag)) | 345 | 8.60k | { | 346 | 8.60k | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 7.28k | { | 348 | 7.28k | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 7.28k | } | 350 | 1.32k | else | 351 | 1.32k | { | 352 | 1.32k | push_back(std::move(obj)); | 353 | 1.32k | decode(out, type_tag, class_tag); | 354 | 1.32k | } | 355 | 8.60k | } | 356 | 14.9k | else | 357 | 14.9k | { | 358 | 14.9k | out = default_value; | 359 | 14.9k | push_back(std::move(obj)); | 360 | 14.9k | } | 361 | 23.5k | | 362 | 23.5k | return (*this); | 363 | 23.5k | } |
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.30k | { | 342 | 1.30k | BER_Object obj = get_next_object(); | 343 | 1.30k | | 344 | 1.30k | if(obj.is_a(type_tag, class_tag)) | 345 | 28 | { | 346 | 28 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 28 | { | 348 | 28 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 28 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 28 | } | 356 | 1.27k | else | 357 | 1.27k | { | 358 | 1.27k | out = default_value; | 359 | 1.27k | push_back(std::move(obj)); | 360 | 1.27k | } | 361 | 1.30k | | 362 | 1.30k | return (*this); | 363 | 1.30k | } |
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 | 791 | { | 342 | 791 | BER_Object obj = get_next_object(); | 343 | 791 | | 344 | 791 | if(obj.is_a(type_tag, class_tag)) | 345 | 761 | { | 346 | 761 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 761 | { | 348 | 761 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 761 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 761 | } | 356 | 30 | else | 357 | 30 | { | 358 | 30 | out = default_value; | 359 | 30 | push_back(std::move(obj)); | 360 | 30 | } | 361 | 791 | | 362 | 791 | return (*this); | 363 | 791 | } |
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 | 35 | { | 342 | 35 | BER_Object obj = get_next_object(); | 343 | 35 | | 344 | 35 | if(obj.is_a(type_tag, class_tag)) | 345 | 18 | { | 346 | 18 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 18 | { | 348 | 18 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 18 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 18 | } | 356 | 17 | else | 357 | 17 | { | 358 | 17 | out = default_value; | 359 | 17 | push_back(std::move(obj)); | 360 | 17 | } | 361 | 35 | | 362 | 35 | return (*this); | 363 | 35 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<bool>(bool&, Botan::ASN1_Tag, Botan::ASN1_Tag, bool const&) Line | Count | Source | 341 | 41.5k | { | 342 | 41.5k | BER_Object obj = get_next_object(); | 343 | 41.5k | | 344 | 41.5k | if(obj.is_a(type_tag, class_tag)) | 345 | 4.11k | { | 346 | 4.11k | 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.11k | else | 351 | 4.11k | { | 352 | 4.11k | push_back(std::move(obj)); | 353 | 4.11k | decode(out, type_tag, class_tag); | 354 | 4.11k | } | 355 | 4.11k | } | 356 | 37.4k | else | 357 | 37.4k | { | 358 | 37.4k | out = default_value; | 359 | 37.4k | push_back(std::move(obj)); | 360 | 37.4k | } | 361 | 41.5k | | 362 | 41.5k | return (*this); | 363 | 41.5k | } |
Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::AlgorithmIdentifier>(Botan::AlgorithmIdentifier&, Botan::ASN1_Tag, Botan::ASN1_Tag, Botan::AlgorithmIdentifier const&) 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.04k | { | 342 | 1.04k | BER_Object obj = get_next_object(); | 343 | 1.04k | | 344 | 1.04k | if(obj.is_a(type_tag, class_tag)) | 345 | 36 | { | 346 | 36 | if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC)) | 347 | 36 | { | 348 | 36 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 349 | 36 | } | 350 | 0 | else | 351 | 0 | { | 352 | 0 | push_back(std::move(obj)); | 353 | 0 | decode(out, type_tag, class_tag); | 354 | 0 | } | 355 | 36 | } | 356 | 1.01k | else | 357 | 1.01k | { | 358 | 1.01k | out = default_value; | 359 | 1.01k | push_back(std::move(obj)); | 360 | 1.01k | } | 361 | 1.04k | | 362 | 1.04k | return (*this); | 363 | 1.04k | } |
|
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.17k | { |
377 | 1.17k | BER_Object obj = get_next_object(); |
378 | 1.17k | |
379 | 1.17k | if(obj.is_a(type_tag, class_tag)) |
380 | 788 | { |
381 | 788 | obj.set_tagging(real_type, real_class); |
382 | 788 | push_back(std::move(obj)); |
383 | 788 | decode(out, real_type, real_class); |
384 | 788 | } |
385 | 388 | else |
386 | 388 | { |
387 | 388 | // Not what we wanted, push it back on the stream |
388 | 388 | out = default_value; |
389 | 388 | push_back(std::move(obj)); |
390 | 388 | } |
391 | 1.17k | |
392 | 1.17k | return (*this); |
393 | 1.17k | } |
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.32k | { |
402 | 7.32k | BER_Decoder list = start_cons(type_tag, class_tag); |
403 | 7.32k | |
404 | 17.3k | while(list.more_items()) |
405 | 9.98k | { |
406 | 9.98k | T value; |
407 | 9.98k | list.decode(value); |
408 | 9.98k | vec.push_back(std::move(value)); |
409 | 9.98k | } |
410 | 7.32k | |
411 | 7.32k | list.end_cons(); |
412 | 7.32k | |
413 | 7.32k | return (*this); |
414 | 7.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_Tag, Botan::ASN1_Tag) Line | Count | Source | 401 | 841 | { | 402 | 841 | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 841 | | 404 | 905 | while(list.more_items()) | 405 | 64 | { | 406 | 64 | T value; | 407 | 64 | list.decode(value); | 408 | 64 | vec.push_back(std::move(value)); | 409 | 64 | } | 410 | 841 | | 411 | 841 | list.end_cons(); | 412 | 841 | | 413 | 841 | return (*this); | 414 | 841 | } |
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.13k | { | 402 | 1.13k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 1.13k | | 404 | 2.88k | while(list.more_items()) | 405 | 1.75k | { | 406 | 1.75k | T value; | 407 | 1.75k | list.decode(value); | 408 | 1.75k | vec.push_back(std::move(value)); | 409 | 1.75k | } | 410 | 1.13k | | 411 | 1.13k | list.end_cons(); | 412 | 1.13k | | 413 | 1.13k | return (*this); | 414 | 1.13k | } |
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.75k | { | 402 | 2.75k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 2.75k | | 404 | 8.30k | while(list.more_items()) | 405 | 5.55k | { | 406 | 5.55k | T value; | 407 | 5.55k | list.decode(value); | 408 | 5.55k | vec.push_back(std::move(value)); | 409 | 5.55k | } | 410 | 2.75k | | 411 | 2.75k | list.end_cons(); | 412 | 2.75k | | 413 | 2.75k | return (*this); | 414 | 2.75k | } |
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 | 884 | { | 402 | 884 | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 884 | | 404 | 2.16k | while(list.more_items()) | 405 | 1.28k | { | 406 | 1.28k | T value; | 407 | 1.28k | list.decode(value); | 408 | 1.28k | vec.push_back(std::move(value)); | 409 | 1.28k | } | 410 | 884 | | 411 | 884 | list.end_cons(); | 412 | 884 | | 413 | 884 | return (*this); | 414 | 884 | } |
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.71k | { | 402 | 1.71k | BER_Decoder list = start_cons(type_tag, class_tag); | 403 | 1.71k | | 404 | 3.04k | while(list.more_items()) | 405 | 1.33k | { | 406 | 1.33k | T value; | 407 | 1.33k | list.decode(value); | 408 | 1.33k | vec.push_back(std::move(value)); | 409 | 1.33k | } | 410 | 1.71k | | 411 | 1.71k | list.end_cons(); | 412 | 1.71k | | 413 | 1.71k | return (*this); | 414 | 1.71k | } |
|
415 | | |
416 | | } |
417 | | |
418 | | #endif |