/src/botan/build/include/public/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 | | #include <botan/mem_ops.h> |
14 | | |
15 | | namespace Botan { |
16 | | |
17 | | class BigInt; |
18 | | |
19 | | /** |
20 | | * BER Decoding Object |
21 | | */ |
22 | | class BOTAN_PUBLIC_API(2, 0) BER_Decoder final { |
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 buf of length len |
31 | | */ |
32 | 26.7k | BER_Decoder(std::span<const uint8_t> buf) : BER_Decoder(buf.data(), buf.size()) {} |
33 | | |
34 | | /** |
35 | | * Set up to BER decode the data in vec |
36 | | */ |
37 | | explicit BER_Decoder(const secure_vector<uint8_t>& vec); |
38 | | |
39 | | /** |
40 | | * Set up to BER decode the data in vec |
41 | | */ |
42 | | explicit BER_Decoder(const std::vector<uint8_t>& vec); |
43 | | |
44 | | /** |
45 | | * Set up to BER decode the data in src |
46 | | */ |
47 | | explicit BER_Decoder(DataSource& src); |
48 | | |
49 | | /** |
50 | | * Set up to BER decode the data in obj |
51 | | */ |
52 | 31.6k | BER_Decoder(const BER_Object& obj) : BER_Decoder(obj.bits(), obj.length()) {} |
53 | | |
54 | | /** |
55 | | * Set up to BER decode the data in obj |
56 | | */ |
57 | 11.4k | BER_Decoder(BER_Object&& obj) : BER_Decoder(std::move(obj), nullptr) {} |
58 | | |
59 | | BER_Decoder(const BER_Decoder& other); |
60 | | |
61 | | BER_Decoder& operator=(const BER_Decoder&) = delete; |
62 | | |
63 | | /** |
64 | | * Get the next object in the data stream. |
65 | | * If EOF, returns an object with type NO_OBJECT. |
66 | | */ |
67 | | BER_Object get_next_object(); |
68 | | |
69 | 32.0k | BER_Decoder& get_next(BER_Object& ber) { |
70 | 32.0k | ber = get_next_object(); |
71 | 32.0k | return (*this); |
72 | 32.0k | } |
73 | | |
74 | | /** |
75 | | * Peek at the next object without removing it from the stream |
76 | | * |
77 | | * If an object has been pushed, then it returns that object. |
78 | | * Otherwise it reads the next object and pushes it. Thus, a you |
79 | | * call peek_next_object followed by push_back without a |
80 | | * subsequent read, it will fail. |
81 | | */ |
82 | | const BER_Object& peek_next_object(); |
83 | | |
84 | | /** |
85 | | * Push an object back onto the stream. Throws if another |
86 | | * object was previously pushed and has not been subsequently |
87 | | * read out. |
88 | | */ |
89 | | void push_back(const BER_Object& obj); |
90 | | |
91 | | /** |
92 | | * Push an object back onto the stream. Throws if another |
93 | | * object was previously pushed and has not been subsequently |
94 | | * read out. |
95 | | */ |
96 | | void push_back(BER_Object&& obj); |
97 | | |
98 | | /** |
99 | | * Return true if there is at least one more item remaining |
100 | | */ |
101 | | bool more_items() const; |
102 | | |
103 | | /** |
104 | | * Verify the stream is concluded, throws otherwise. |
105 | | * Returns (*this) |
106 | | */ |
107 | | BER_Decoder& verify_end(); |
108 | | |
109 | | /** |
110 | | * Verify the stream is concluded, throws otherwise. |
111 | | * Returns (*this) |
112 | | */ |
113 | | BER_Decoder& verify_end(std::string_view err_msg); |
114 | | |
115 | | /** |
116 | | * Discard any data that remains unread |
117 | | * Returns (*this) |
118 | | */ |
119 | | BER_Decoder& discard_remaining(); |
120 | | |
121 | | BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag); |
122 | | |
123 | 547k | BER_Decoder start_sequence() { return start_cons(ASN1_Type::Sequence, ASN1_Class::Universal); } |
124 | | |
125 | 126k | BER_Decoder start_set() { return start_cons(ASN1_Type::Set, ASN1_Class::Universal); } |
126 | | |
127 | 9.81k | BER_Decoder start_context_specific(uint32_t tag) { |
128 | 9.81k | return start_cons(ASN1_Type(tag), ASN1_Class::ContextSpecific); |
129 | 9.81k | } |
130 | | |
131 | 0 | BER_Decoder start_explicit_context_specific(uint32_t tag) { |
132 | 0 | return start_cons(ASN1_Type(tag), ASN1_Class::ExplicitContextSpecific); |
133 | 0 | } |
134 | | |
135 | | /** |
136 | | * Finish decoding a constructed data, throws if any data remains. |
137 | | * Returns the parent of *this (ie the object on which start_cons was called). |
138 | | */ |
139 | | BER_Decoder& end_cons(); |
140 | | |
141 | | /** |
142 | | * Get next object and copy value to POD type |
143 | | * Asserts value length is equal to POD type sizeof. |
144 | | * Asserts Type tag and optional Class tag according to parameters. |
145 | | * Copy value to POD type (struct, union, C-style array, std::array, etc.). |
146 | | * @param out POD type reference where to copy object value |
147 | | * @param type_tag ASN1_Type enum to assert type on object read |
148 | | * @param class_tag ASN1_Type enum to assert class on object read (default: CONTEXT_SPECIFIC) |
149 | | * @return this reference |
150 | | */ |
151 | | template <typename T> |
152 | | BER_Decoder& get_next_value(T& out, ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::ContextSpecific) |
153 | | requires std::is_standard_layout<T>::value && std::is_trivial<T>::value |
154 | | { |
155 | | BER_Object obj = get_next_object(); |
156 | | obj.assert_is_a(type_tag, class_tag); |
157 | | |
158 | | if(obj.length() != sizeof(T)) { |
159 | | throw BER_Decoding_Error("Size mismatch. Object value size is " + std::to_string(obj.length()) + |
160 | | "; Output type size is " + std::to_string(sizeof(T))); |
161 | | } |
162 | | |
163 | | copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length()); |
164 | | |
165 | | return (*this); |
166 | | } |
167 | | |
168 | | /* |
169 | | * Save all the bytes remaining in the source |
170 | | */ |
171 | | template <typename Alloc> |
172 | 167k | BER_Decoder& raw_bytes(std::vector<uint8_t, Alloc>& out) { |
173 | 167k | out.clear(); |
174 | 167k | uint8_t buf; |
175 | 18.0M | while(m_source->read_byte(buf)) { |
176 | 17.8M | out.push_back(buf); |
177 | 17.8M | } |
178 | 167k | return (*this); |
179 | 167k | } |
180 | | |
181 | | BER_Decoder& decode_null(); |
182 | | |
183 | | /** |
184 | | * Decode a BER encoded BOOLEAN |
185 | | */ |
186 | 674 | BER_Decoder& decode(bool& out) { return decode(out, ASN1_Type::Boolean, ASN1_Class::Universal); } |
187 | | |
188 | | /* |
189 | | * Decode a small BER encoded INTEGER |
190 | | */ |
191 | 27.6k | BER_Decoder& decode(size_t& out) { return decode(out, ASN1_Type::Integer, ASN1_Class::Universal); } |
192 | | |
193 | | /* |
194 | | * Decode a BER encoded INTEGER |
195 | | */ |
196 | 99.2k | BER_Decoder& decode(BigInt& out) { return decode(out, ASN1_Type::Integer, ASN1_Class::Universal); } |
197 | | |
198 | 2.78k | std::vector<uint8_t> get_next_octet_string() { |
199 | 2.78k | std::vector<uint8_t> out_vec; |
200 | 2.78k | decode(out_vec, ASN1_Type::OctetString); |
201 | 2.78k | return out_vec; |
202 | 2.78k | } |
203 | | |
204 | | /* |
205 | | * BER decode a BIT STRING or OCTET STRING |
206 | | */ |
207 | | template <typename Alloc> |
208 | 142k | BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Type real_type) { |
209 | 142k | return decode(out, real_type, real_type, ASN1_Class::Universal); |
210 | 142k | } 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 | 208 | 128k | BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Type real_type) { | 209 | 128k | return decode(out, real_type, real_type, ASN1_Class::Universal); | 210 | 128k | } |
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 | 208 | 13.9k | BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Type real_type) { | 209 | 13.9k | return decode(out, real_type, real_type, ASN1_Class::Universal); | 210 | 13.9k | } |
|
211 | | |
212 | | BER_Decoder& decode(bool& v, ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
213 | | |
214 | | BER_Decoder& decode(size_t& v, ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
215 | | |
216 | | BER_Decoder& decode(BigInt& v, ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
217 | | |
218 | | BER_Decoder& decode(std::vector<uint8_t>& v, |
219 | | ASN1_Type real_type, |
220 | | ASN1_Type type_tag, |
221 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
222 | | |
223 | | BER_Decoder& decode(secure_vector<uint8_t>& v, |
224 | | ASN1_Type real_type, |
225 | | ASN1_Type type_tag, |
226 | | ASN1_Class class_tag = ASN1_Class::ContextSpecific); |
227 | | |
228 | | BER_Decoder& decode(ASN1_Object& obj, |
229 | | ASN1_Type type_tag = ASN1_Type::NoObject, |
230 | | ASN1_Class class_tag = ASN1_Class::NoObject); |
231 | | |
232 | | /** |
233 | | * Decode an integer value which is typed as an octet string |
234 | | */ |
235 | | BER_Decoder& decode_octet_string_bigint(BigInt& b); |
236 | | |
237 | | uint64_t decode_constrained_integer(ASN1_Type type_tag, ASN1_Class class_tag, size_t T_bytes); |
238 | | |
239 | | template <typename T> |
240 | 0 | BER_Decoder& decode_integer_type(T& out) { |
241 | 0 | return decode_integer_type<T>(out, ASN1_Type::Integer, ASN1_Class::Universal); |
242 | 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&) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned int>(unsigned int&) |
243 | | |
244 | | template <typename T> |
245 | 0 | BER_Decoder& decode_integer_type(T& out, ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::ContextSpecific) { |
246 | 0 | out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out))); |
247 | 0 | return (*this); |
248 | 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) Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_integer_type<unsigned int>(unsigned int&, Botan::ASN1_Type, Botan::ASN1_Class) |
249 | | |
250 | | template <typename T> |
251 | | BER_Decoder& decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value = T()); |
252 | | |
253 | | template <typename T> |
254 | | BER_Decoder& decode_optional_implicit(T& out, |
255 | | ASN1_Type type_tag, |
256 | | ASN1_Class class_tag, |
257 | | ASN1_Type real_type, |
258 | | ASN1_Class real_class, |
259 | | const T& default_value = T()); |
260 | | |
261 | | template <typename T> |
262 | | BER_Decoder& decode_list(std::vector<T>& out, |
263 | | ASN1_Type type_tag = ASN1_Type::Sequence, |
264 | | ASN1_Class class_tag = ASN1_Class::Universal); |
265 | | |
266 | | template <typename T> |
267 | | bool decode_optional_list(std::vector<T>& out, |
268 | | ASN1_Type type_tag = ASN1_Type::Sequence, |
269 | | ASN1_Class class_tag = ASN1_Class::Universal); |
270 | | |
271 | | template <typename T> |
272 | 23.3k | BER_Decoder& decode_and_check(const T& expected, std::string_view error_msg) { |
273 | 23.3k | T actual; |
274 | 23.3k | decode(actual); |
275 | | |
276 | 23.3k | if(actual != expected) { |
277 | 471 | throw Decoding_Error(error_msg); |
278 | 471 | } |
279 | | |
280 | 22.8k | return (*this); |
281 | 23.3k | } Botan::BER_Decoder& Botan::BER_Decoder::decode_and_check<unsigned long>(unsigned long const&, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Line | Count | Source | 272 | 19.3k | BER_Decoder& decode_and_check(const T& expected, std::string_view error_msg) { | 273 | 19.3k | T actual; | 274 | 19.3k | decode(actual); | 275 | | | 276 | 19.3k | if(actual != expected) { | 277 | 179 | throw Decoding_Error(error_msg); | 278 | 179 | } | 279 | | | 280 | 19.1k | return (*this); | 281 | 19.3k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_and_check<Botan::OID>(Botan::OID const&, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Line | Count | Source | 272 | 3.98k | BER_Decoder& decode_and_check(const T& expected, std::string_view error_msg) { | 273 | 3.98k | T actual; | 274 | 3.98k | decode(actual); | 275 | | | 276 | 3.98k | if(actual != expected) { | 277 | 292 | throw Decoding_Error(error_msg); | 278 | 292 | } | 279 | | | 280 | 3.69k | return (*this); | 281 | 3.98k | } |
|
282 | | |
283 | | /* |
284 | | * Decode an OPTIONAL string type |
285 | | */ |
286 | | template <typename Alloc> |
287 | | BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out, |
288 | | ASN1_Type real_type, |
289 | | uint32_t expected_tag, |
290 | 37.1k | ASN1_Class class_tag = ASN1_Class::ContextSpecific) { |
291 | 37.1k | BER_Object obj = get_next_object(); |
292 | | |
293 | 37.1k | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); |
294 | | |
295 | 37.1k | if(obj.is_a(type_tag, class_tag)) { |
296 | 1.87k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { |
297 | 705 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); |
298 | 1.17k | } else { |
299 | 1.17k | push_back(std::move(obj)); |
300 | 1.17k | decode(out, real_type, type_tag, class_tag); |
301 | 1.17k | } |
302 | 35.3k | } else { |
303 | 35.3k | out.clear(); |
304 | 35.3k | push_back(std::move(obj)); |
305 | 35.3k | } |
306 | | |
307 | 37.1k | return (*this); |
308 | 37.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_Type, unsigned int, Botan::ASN1_Class) Line | Count | Source | 290 | 36.2k | ASN1_Class class_tag = ASN1_Class::ContextSpecific) { | 291 | 36.2k | BER_Object obj = get_next_object(); | 292 | | | 293 | 36.2k | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); | 294 | | | 295 | 36.2k | if(obj.is_a(type_tag, class_tag)) { | 296 | 1.18k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 297 | 16 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 298 | 1.17k | } else { | 299 | 1.17k | push_back(std::move(obj)); | 300 | 1.17k | decode(out, real_type, type_tag, class_tag); | 301 | 1.17k | } | 302 | 35.0k | } else { | 303 | 35.0k | out.clear(); | 304 | 35.0k | push_back(std::move(obj)); | 305 | 35.0k | } | 306 | | | 307 | 36.2k | return (*this); | 308 | 36.2k | } |
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 | 290 | 939 | ASN1_Class class_tag = ASN1_Class::ContextSpecific) { | 291 | 939 | BER_Object obj = get_next_object(); | 292 | | | 293 | 939 | ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag); | 294 | | | 295 | 939 | if(obj.is_a(type_tag, class_tag)) { | 296 | 689 | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 297 | 689 | BER_Decoder(std::move(obj)).decode(out, real_type).verify_end(); | 298 | 689 | } else { | 299 | 0 | push_back(std::move(obj)); | 300 | 0 | decode(out, real_type, type_tag, class_tag); | 301 | 0 | } | 302 | 689 | } else { | 303 | 250 | out.clear(); | 304 | 250 | push_back(std::move(obj)); | 305 | 250 | } | 306 | | | 307 | 939 | return (*this); | 308 | 939 | } |
|
309 | | |
310 | | template <typename Alloc> |
311 | | BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out, |
312 | | ASN1_Type real_type, |
313 | | ASN1_Type expected_tag, |
314 | 786 | ASN1_Class class_tag = ASN1_Class::ContextSpecific) { |
315 | 786 | return decode_optional_string(out, real_type, static_cast<uint32_t>(expected_tag), class_tag); |
316 | 786 | } |
317 | | |
318 | | private: |
319 | | BER_Decoder(BER_Object&& obj, BER_Decoder* parent); |
320 | | |
321 | | BER_Decoder* m_parent = nullptr; |
322 | | BER_Object m_pushed; |
323 | | // either m_data_src.get() or an unowned pointer |
324 | | DataSource* m_source; |
325 | | mutable std::unique_ptr<DataSource> m_data_src; |
326 | | }; |
327 | | |
328 | | /* |
329 | | * Decode an OPTIONAL or DEFAULT element |
330 | | */ |
331 | | template <typename T> |
332 | 98.6k | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { |
333 | 98.6k | BER_Object obj = get_next_object(); |
334 | | |
335 | 98.6k | if(obj.is_a(type_tag, class_tag)) { |
336 | 22.9k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { |
337 | 8.28k | BER_Decoder(std::move(obj)).decode(out).verify_end(); |
338 | 14.6k | } else { |
339 | 14.6k | push_back(std::move(obj)); |
340 | 14.6k | decode(out, type_tag, class_tag); |
341 | 14.6k | } |
342 | 75.7k | } else { |
343 | 75.7k | out = default_value; |
344 | 75.7k | push_back(std::move(obj)); |
345 | 75.7k | } |
346 | | |
347 | 98.6k | return (*this); |
348 | 98.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 | 332 | 37.1k | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 37.1k | BER_Object obj = get_next_object(); | 334 | | | 335 | 37.1k | if(obj.is_a(type_tag, class_tag)) { | 336 | 8.62k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 6.09k | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 6.09k | } else { | 339 | 2.53k | push_back(std::move(obj)); | 340 | 2.53k | decode(out, type_tag, class_tag); | 341 | 2.53k | } | 342 | 28.5k | } else { | 343 | 28.5k | out = default_value; | 344 | 28.5k | push_back(std::move(obj)); | 345 | 28.5k | } | 346 | | | 347 | 37.1k | return (*this); | 348 | 37.1k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::AlgorithmIdentifier>(Botan::AlgorithmIdentifier&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::AlgorithmIdentifier const&) Line | Count | Source | 332 | 261 | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 261 | BER_Object obj = get_next_object(); | 334 | | | 335 | 261 | if(obj.is_a(type_tag, class_tag)) { | 336 | 241 | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 241 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 241 | } else { | 339 | 0 | push_back(std::move(obj)); | 340 | 0 | decode(out, type_tag, class_tag); | 341 | 0 | } | 342 | 241 | } else { | 343 | 20 | out = default_value; | 344 | 20 | push_back(std::move(obj)); | 345 | 20 | } | 346 | | | 347 | 261 | return (*this); | 348 | 261 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::OID>(Botan::OID&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::OID const&) Line | Count | Source | 332 | 948 | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 948 | BER_Object obj = get_next_object(); | 334 | | | 335 | 948 | if(obj.is_a(type_tag, class_tag)) { | 336 | 20 | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 20 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 20 | } else { | 339 | 0 | push_back(std::move(obj)); | 340 | 0 | decode(out, type_tag, class_tag); | 341 | 0 | } | 342 | 928 | } else { | 343 | 928 | out = default_value; | 344 | 928 | push_back(std::move(obj)); | 345 | 928 | } | 346 | | | 347 | 948 | return (*this); | 348 | 948 | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<bool>(bool&, Botan::ASN1_Type, Botan::ASN1_Class, bool const&) Line | Count | Source | 332 | 55.9k | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 55.9k | BER_Object obj = get_next_object(); | 334 | | | 335 | 55.9k | if(obj.is_a(type_tag, class_tag)) { | 336 | 12.0k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 0 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 12.0k | } else { | 339 | 12.0k | push_back(std::move(obj)); | 340 | 12.0k | decode(out, type_tag, class_tag); | 341 | 12.0k | } | 342 | 43.8k | } else { | 343 | 43.8k | out = default_value; | 344 | 43.8k | push_back(std::move(obj)); | 345 | 43.8k | } | 346 | | | 347 | 55.9k | return (*this); | 348 | 55.9k | } |
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 | 332 | 2.59k | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 2.59k | BER_Object obj = get_next_object(); | 334 | | | 335 | 2.59k | if(obj.is_a(type_tag, class_tag)) { | 336 | 243 | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 243 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 243 | } else { | 339 | 0 | push_back(std::move(obj)); | 340 | 0 | decode(out, type_tag, class_tag); | 341 | 0 | } | 342 | 2.35k | } else { | 343 | 2.35k | out = default_value; | 344 | 2.35k | push_back(std::move(obj)); | 345 | 2.35k | } | 346 | | | 347 | 2.59k | return (*this); | 348 | 2.59k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<Botan::Extensions>(Botan::Extensions&, Botan::ASN1_Type, Botan::ASN1_Class, Botan::Extensions const&) Line | Count | Source | 332 | 1.70k | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 1.70k | BER_Object obj = get_next_object(); | 334 | | | 335 | 1.70k | if(obj.is_a(type_tag, class_tag)) { | 336 | 1.68k | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 1.68k | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 1.68k | } else { | 339 | 0 | push_back(std::move(obj)); | 340 | 0 | decode(out, type_tag, class_tag); | 341 | 0 | } | 342 | 1.68k | } else { | 343 | 14 | out = default_value; | 344 | 14 | push_back(std::move(obj)); | 345 | 14 | } | 346 | | | 347 | 1.70k | return (*this); | 348 | 1.70k | } |
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 | 332 | 9 | BER_Decoder& BER_Decoder::decode_optional(T& out, ASN1_Type type_tag, ASN1_Class class_tag, const T& default_value) { | 333 | 9 | BER_Object obj = get_next_object(); | 334 | | | 335 | 9 | if(obj.is_a(type_tag, class_tag)) { | 336 | 1 | if(class_tag == ASN1_Class::ExplicitContextSpecific) { | 337 | 1 | BER_Decoder(std::move(obj)).decode(out).verify_end(); | 338 | 1 | } else { | 339 | 0 | push_back(std::move(obj)); | 340 | 0 | decode(out, type_tag, class_tag); | 341 | 0 | } | 342 | 8 | } else { | 343 | 8 | out = default_value; | 344 | 8 | push_back(std::move(obj)); | 345 | 8 | } | 346 | | | 347 | 9 | return (*this); | 348 | 9 | } |
|
349 | | |
350 | | /* |
351 | | * Decode an OPTIONAL or DEFAULT element |
352 | | */ |
353 | | template <typename T> |
354 | | BER_Decoder& BER_Decoder::decode_optional_implicit(T& out, |
355 | | ASN1_Type type_tag, |
356 | | ASN1_Class class_tag, |
357 | | ASN1_Type real_type, |
358 | | ASN1_Class real_class, |
359 | 5.93k | const T& default_value) { |
360 | 5.93k | BER_Object obj = get_next_object(); |
361 | | |
362 | 5.93k | if(obj.is_a(type_tag, class_tag)) { |
363 | 4.16k | obj.set_tagging(real_type, real_class); |
364 | 4.16k | push_back(std::move(obj)); |
365 | 4.16k | decode(out, real_type, real_class); |
366 | 4.16k | } else { |
367 | | // Not what we wanted, push it back on the stream |
368 | 1.77k | out = default_value; |
369 | 1.77k | push_back(std::move(obj)); |
370 | 1.77k | } |
371 | | |
372 | 5.93k | return (*this); |
373 | 5.93k | } |
374 | | |
375 | | /* |
376 | | * Decode a list of homogenously typed values |
377 | | */ |
378 | | template <typename T> |
379 | 16.5k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { |
380 | 16.5k | BER_Decoder list = start_cons(type_tag, class_tag); |
381 | | |
382 | 42.0k | while(list.more_items()) { |
383 | 25.4k | T value; |
384 | 25.4k | list.decode(value); |
385 | 25.4k | vec.push_back(std::move(value)); |
386 | 25.4k | } |
387 | | |
388 | 16.5k | list.end_cons(); |
389 | | |
390 | 16.5k | return (*this); |
391 | 16.5k | } 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 | 379 | 2.29k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 2.29k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 5.77k | while(list.more_items()) { | 383 | 3.47k | T value; | 384 | 3.47k | list.decode(value); | 385 | 3.47k | vec.push_back(std::move(value)); | 386 | 3.47k | } | 387 | | | 388 | 2.29k | list.end_cons(); | 389 | | | 390 | 2.29k | return (*this); | 391 | 2.29k | } |
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 | 379 | 5.30k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 5.30k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 18.1k | while(list.more_items()) { | 383 | 12.8k | T value; | 384 | 12.8k | list.decode(value); | 385 | 12.8k | vec.push_back(std::move(value)); | 386 | 12.8k | } | 387 | | | 388 | 5.30k | list.end_cons(); | 389 | | | 390 | 5.30k | return (*this); | 391 | 5.30k | } |
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 | 379 | 1.28k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 1.28k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 2.88k | while(list.more_items()) { | 383 | 1.60k | T value; | 384 | 1.60k | list.decode(value); | 385 | 1.60k | vec.push_back(std::move(value)); | 386 | 1.60k | } | 387 | | | 388 | 1.28k | list.end_cons(); | 389 | | | 390 | 1.28k | return (*this); | 391 | 1.28k | } |
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 | 379 | 4.79k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 4.79k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 10.7k | while(list.more_items()) { | 383 | 5.98k | T value; | 384 | 5.98k | list.decode(value); | 385 | 5.98k | vec.push_back(std::move(value)); | 386 | 5.98k | } | 387 | | | 388 | 4.79k | list.end_cons(); | 389 | | | 390 | 4.79k | return (*this); | 391 | 4.79k | } |
Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::Cert_Extension::TNAuthList::Entry>(std::__1::vector<Botan::Cert_Extension::TNAuthList::Entry, std::__1::allocator<Botan::Cert_Extension::TNAuthList::Entry> >&, Botan::ASN1_Type, Botan::ASN1_Class) Line | Count | Source | 379 | 1.16k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 1.16k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 2.70k | while(list.more_items()) { | 383 | 1.53k | T value; | 384 | 1.53k | list.decode(value); | 385 | 1.53k | vec.push_back(std::move(value)); | 386 | 1.53k | } | 387 | | | 388 | 1.16k | list.end_cons(); | 389 | | | 390 | 1.16k | return (*this); | 391 | 1.16k | } |
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 | 379 | 1.71k | BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { | 380 | 1.71k | BER_Decoder list = start_cons(type_tag, class_tag); | 381 | | | 382 | 1.73k | while(list.more_items()) { | 383 | 16 | T value; | 384 | 16 | list.decode(value); | 385 | 16 | vec.push_back(std::move(value)); | 386 | 16 | } | 387 | | | 388 | 1.71k | list.end_cons(); | 389 | | | 390 | 1.71k | return (*this); | 391 | 1.71k | } |
Unexecuted instantiation: Botan::BER_Decoder& Botan::BER_Decoder::decode_list<Botan::X509_Certificate>(std::__1::vector<Botan::X509_Certificate, std::__1::allocator<Botan::X509_Certificate> >&, Botan::ASN1_Type, Botan::ASN1_Class) |
392 | | |
393 | | /* |
394 | | * Decode an optional list of homogenously typed values |
395 | | */ |
396 | | template <typename T> |
397 | 9.98k | bool BER_Decoder::decode_optional_list(std::vector<T>& vec, ASN1_Type type_tag, ASN1_Class class_tag) { |
398 | 9.98k | if(peek_next_object().is_a(type_tag, class_tag)) { |
399 | 5.30k | decode_list(vec, type_tag, class_tag); |
400 | 5.30k | return true; |
401 | 5.30k | } |
402 | | |
403 | 4.68k | return false; |
404 | 9.98k | } |
405 | | |
406 | | } // namespace Botan |
407 | | |
408 | | #endif |