Coverage Report

Created: 2020-05-23 13:54

/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
23.6k
         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
9.42k
         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
23.2k
         {
68
23.2k
         ber = get_next_object();
69
23.2k
         return (*this);
70
23.2k
         }
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
115k
         {
158
115k
         out.clear();
159
115k
         uint8_t buf;
160
10.7M
         while(m_source->read_byte(buf))
161
10.6M
            out.push_back(buf);
162
115k
         return (*this);
163
115k
         }
164
165
      BER_Decoder& decode_null();
166
167
      /**
168
      * Decode a BER encoded BOOLEAN
169
      */
170
      BER_Decoder& decode(bool& out)
171
613
         {
172
613
         return decode(out, BOOLEAN, UNIVERSAL);
173
613
         }
174
175
      /*
176
      * Decode a small BER encoded INTEGER
177
      */
178
      BER_Decoder& decode(size_t& out)
179
10.5k
         {
180
10.5k
         return decode(out, INTEGER, UNIVERSAL);
181
10.5k
         }
182
183
      /*
184
      * Decode a BER encoded INTEGER
185
      */
186
      BER_Decoder& decode(BigInt& out)
187
43.1k
         {
188
43.1k
         return decode(out, INTEGER, UNIVERSAL);
189
43.1k
         }
190
191
      std::vector<uint8_t> get_next_octet_string()
192
2.27k
         {
193
2.27k
         std::vector<uint8_t> out_vec;
194
2.27k
         decode(out_vec, OCTET_STRING);
195
2.27k
         return out_vec;
196
2.27k
         }
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
97.3k
         {
204
97.3k
         return decode(out, real_type, real_type, UNIVERSAL);
205
97.3k
         }
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.30k
         {
204
4.30k
         return decode(out, real_type, real_type, UNIVERSAL);
205
4.30k
         }
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
93.0k
         {
204
93.0k
         return decode(out, real_type, real_type, UNIVERSAL);
205
93.0k
         }
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
6.88k
         {
280
6.88k
         T actual;
281
6.88k
         decode(actual);
282
6.88k
283
6.88k
         if(actual != expected)
284
295
            throw Decoding_Error(error_msg);
285
6.58k
286
6.58k
         return (*this);
287
6.58k
         }
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
2.87k
         {
280
2.87k
         T actual;
281
2.87k
         decode(actual);
282
2.87k
283
2.87k
         if(actual != expected)
284
171
            throw Decoding_Error(error_msg);
285
2.70k
286
2.70k
         return (*this);
287
2.70k
         }
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.00k
         {
280
4.00k
         T actual;
281
4.00k
         decode(actual);
282
4.00k
283
4.00k
         if(actual != expected)
284
124
            throw Decoding_Error(error_msg);
285
3.88k
286
3.88k
         return (*this);
287
3.88k
         }
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
26.4k
         {
298
26.4k
         BER_Object obj = get_next_object();
299
26.4k
300
26.4k
         ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
301
26.4k
302
26.4k
         if(obj.is_a(type_tag, class_tag))
303
1.57k
            {
304
1.57k
            if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
305
997
               {
306
997
               BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
307
997
               }
308
575
            else
309
575
               {
310
575
               push_back(std::move(obj));
311
575
               decode(out, real_type, type_tag, class_tag);
312
575
               }
313
1.57k
            }
314
24.9k
         else
315
24.9k
            {
316
24.9k
            out.clear();
317
24.9k
            push_back(std::move(obj));
318
24.9k
            }
319
26.4k
320
26.4k
         return (*this);
321
26.4k
         }
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
25.4k
         {
298
25.4k
         BER_Object obj = get_next_object();
299
25.4k
300
25.4k
         ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
301
25.4k
302
25.4k
         if(obj.is_a(type_tag, class_tag))
303
889
            {
304
889
            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
575
            else
309
575
               {
310
575
               push_back(std::move(obj));
311
575
               decode(out, real_type, type_tag, class_tag);
312
575
               }
313
889
            }
314
24.5k
         else
315
24.5k
            {
316
24.5k
            out.clear();
317
24.5k
            push_back(std::move(obj));
318
24.5k
            }
319
25.4k
320
25.4k
         return (*this);
321
25.4k
         }
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.01k
         {
298
1.01k
         BER_Object obj = get_next_object();
299
1.01k
300
1.01k
         ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
301
1.01k
302
1.01k
         if(obj.is_a(type_tag, class_tag))
303
683
            {
304
683
            if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
305
683
               {
306
683
               BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
307
683
               }
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
683
            }
314
330
         else
315
330
            {
316
330
            out.clear();
317
330
            push_back(std::move(obj));
318
330
            }
319
1.01k
320
1.01k
         return (*this);
321
1.01k
         }
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
59.1k
   {
342
59.1k
   BER_Object obj = get_next_object();
343
59.1k
344
59.1k
   if(obj.is_a(type_tag, class_tag))
345
12.0k
      {
346
12.0k
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
6.97k
         {
348
6.97k
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
6.97k
         }
350
5.08k
      else
351
5.08k
         {
352
5.08k
         push_back(std::move(obj));
353
5.08k
         decode(out, type_tag, class_tag);
354
5.08k
         }
355
12.0k
      }
356
47.0k
   else
357
47.0k
      {
358
47.0k
      out = default_value;
359
47.0k
      push_back(std::move(obj));
360
47.0k
      }
361
59.1k
362
59.1k
   return (*this);
363
59.1k
   }
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
20.2k
   {
342
20.2k
   BER_Object obj = get_next_object();
343
20.2k
344
20.2k
   if(obj.is_a(type_tag, class_tag))
345
7.19k
      {
346
7.19k
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
6.04k
         {
348
6.04k
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
6.04k
         }
350
1.15k
      else
351
1.15k
         {
352
1.15k
         push_back(std::move(obj));
353
1.15k
         decode(out, type_tag, class_tag);
354
1.15k
         }
355
7.19k
      }
356
13.0k
   else
357
13.0k
      {
358
13.0k
      out = default_value;
359
13.0k
      push_back(std::move(obj));
360
13.0k
      }
361
20.2k
362
20.2k
   return (*this);
363
20.2k
   }
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.20k
   {
342
1.20k
   BER_Object obj = get_next_object();
343
1.20k
344
1.20k
   if(obj.is_a(type_tag, class_tag))
345
93
      {
346
93
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
93
         {
348
93
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
93
         }
350
0
      else
351
0
         {
352
0
         push_back(std::move(obj));
353
0
         decode(out, type_tag, class_tag);
354
0
         }
355
93
      }
356
1.11k
   else
357
1.11k
      {
358
1.11k
      out = default_value;
359
1.11k
      push_back(std::move(obj));
360
1.11k
      }
361
1.20k
362
1.20k
   return (*this);
363
1.20k
   }
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
714
   {
342
714
   BER_Object obj = get_next_object();
343
714
344
714
   if(obj.is_a(type_tag, class_tag))
345
694
      {
346
694
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
694
         {
348
694
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
694
         }
350
0
      else
351
0
         {
352
0
         push_back(std::move(obj));
353
0
         decode(out, type_tag, class_tag);
354
0
         }
355
694
      }
356
20
   else
357
20
      {
358
20
      out = default_value;
359
20
      push_back(std::move(obj));
360
20
      }
361
714
362
714
   return (*this);
363
714
   }
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
31
   {
342
31
   BER_Object obj = get_next_object();
343
31
344
31
   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
14
   else
357
14
      {
358
14
      out = default_value;
359
14
      push_back(std::move(obj));
360
14
      }
361
31
362
31
   return (*this);
363
31
   }
Botan::BER_Decoder& Botan::BER_Decoder::decode_optional<bool>(bool&, Botan::ASN1_Tag, Botan::ASN1_Tag, bool const&)
Line
Count
Source
341
35.8k
   {
342
35.8k
   BER_Object obj = get_next_object();
343
35.8k
344
35.8k
   if(obj.is_a(type_tag, class_tag))
345
3.92k
      {
346
3.92k
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
0
         {
348
0
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
0
         }
350
3.92k
      else
351
3.92k
         {
352
3.92k
         push_back(std::move(obj));
353
3.92k
         decode(out, type_tag, class_tag);
354
3.92k
         }
355
3.92k
      }
356
31.8k
   else
357
31.8k
      {
358
31.8k
      out = default_value;
359
31.8k
      push_back(std::move(obj));
360
31.8k
      }
361
35.8k
362
35.8k
   return (*this);
363
35.8k
   }
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
101
   {
342
101
   BER_Object obj = get_next_object();
343
101
344
101
   if(obj.is_a(type_tag, class_tag))
345
98
      {
346
98
      if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347
98
         {
348
98
         BER_Decoder(std::move(obj)).decode(out).verify_end();
349
98
         }
350
0
      else
351
0
         {
352
0
         push_back(std::move(obj));
353
0
         decode(out, type_tag, class_tag);
354
0
         }
355
98
      }
356
3
   else
357
3
      {
358
3
      out = default_value;
359
3
      push_back(std::move(obj));
360
3
      }
361
101
362
101
   return (*this);
363
101
   }
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.01k
   {
342
1.01k
   BER_Object obj = get_next_object();
343
1.01k
344
1.01k
   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
982
   else
357
982
      {
358
982
      out = default_value;
359
982
      push_back(std::move(obj));
360
982
      }
361
1.01k
362
1.01k
   return (*this);
363
1.01k
   }
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.00k
   {
377
1.00k
   BER_Object obj = get_next_object();
378
1.00k
379
1.00k
   if(obj.is_a(type_tag, class_tag))
380
614
      {
381
614
      obj.set_tagging(real_type, real_class);
382
614
      push_back(std::move(obj));
383
614
      decode(out, real_type, real_class);
384
614
      }
385
392
   else
386
392
      {
387
392
      // Not what we wanted, push it back on the stream
388
392
      out = default_value;
389
392
      push_back(std::move(obj));
390
392
      }
391
1.00k
392
1.00k
   return (*this);
393
1.00k
   }
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
6.56k
   {
402
6.56k
   BER_Decoder list = start_cons(type_tag, class_tag);
403
6.56k
404
14.7k
   while(list.more_items())
405
8.18k
      {
406
8.18k
      T value;
407
8.18k
      list.decode(value);
408
8.18k
      vec.push_back(std::move(value));
409
8.18k
      }
410
6.56k
411
6.56k
   list.end_cons();
412
6.56k
413
6.56k
   return (*this);
414
6.56k
   }
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
754
   {
402
754
   BER_Decoder list = start_cons(type_tag, class_tag);
403
754
404
803
   while(list.more_items())
405
49
      {
406
49
      T value;
407
49
      list.decode(value);
408
49
      vec.push_back(std::move(value));
409
49
      }
410
754
411
754
   list.end_cons();
412
754
413
754
   return (*this);
414
754
   }
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.05k
   {
402
1.05k
   BER_Decoder list = start_cons(type_tag, class_tag);
403
1.05k
404
2.48k
   while(list.more_items())
405
1.42k
      {
406
1.42k
      T value;
407
1.42k
      list.decode(value);
408
1.42k
      vec.push_back(std::move(value));
409
1.42k
      }
410
1.05k
411
1.05k
   list.end_cons();
412
1.05k
413
1.05k
   return (*this);
414
1.05k
   }
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.29k
   {
402
2.29k
   BER_Decoder list = start_cons(type_tag, class_tag);
403
2.29k
404
6.73k
   while(list.more_items())
405
4.44k
      {
406
4.44k
      T value;
407
4.44k
      list.decode(value);
408
4.44k
      vec.push_back(std::move(value));
409
4.44k
      }
410
2.29k
411
2.29k
   list.end_cons();
412
2.29k
413
2.29k
   return (*this);
414
2.29k
   }
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
983
   {
402
983
   BER_Decoder list = start_cons(type_tag, class_tag);
403
983
404
2.10k
   while(list.more_items())
405
1.11k
      {
406
1.11k
      T value;
407
1.11k
      list.decode(value);
408
1.11k
      vec.push_back(std::move(value));
409
1.11k
      }
410
983
411
983
   list.end_cons();
412
983
413
983
   return (*this);
414
983
   }
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.47k
   {
402
1.47k
   BER_Decoder list = start_cons(type_tag, class_tag);
403
1.47k
404
2.62k
   while(list.more_items())
405
1.14k
      {
406
1.14k
      T value;
407
1.14k
      list.decode(value);
408
1.14k
      vec.push_back(std::move(value));
409
1.14k
      }
410
1.47k
411
1.47k
   list.end_cons();
412
1.47k
413
1.47k
   return (*this);
414
1.47k
   }
415
416
}
417
418
#endif