Embedded Template Library 1.0
Loading...
Searching...
No Matches
base64_decoder.h
1//*************************************************************************
3//*************************************************************************///\file
4
5/******************************************************************************
6The MIT License(MIT)
7Embedded Template Library.
8https://github.com/ETLCPP/etl
9https://www.etlcpp.com
10Copyright(c) 2024 John Wellbelove
11Permission is hereby granted, free of charge, to any person obtaining a copy
12of this software and associated documentation files(the "Software"), to deal
13in the Software without restriction, including without limitation the rights
14to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
15copies of the Software, and to permit persons to whom the Software is
16furnished to do so, subject to the following conditions :
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25SOFTWARE.
26******************************************************************************/
27
28#ifndef ETL_BASE64_DECODER_INCLUDED
29#define ETL_BASE64_DECODER_INCLUDED
30
31#include "platform.h"
32#include "algorithm.h"
33#include "binary.h"
34#include "delegate.h"
35#include "enum_type.h"
36#include "error_handler.h"
37#include "integral_limits.h"
38#include "iterator.h"
39#include "span.h"
40#include "static_assert.h"
41#include "type_traits.h"
42
43#include "base64.h"
44
45#include <stdint.h>
46
47#if ETL_USING_STL
48 #include <iterator>
49#endif
50
51#define ETL_IS_8_BIT_INTEGRAL(Type) \
52 (etl::is_integral<typename etl::remove_cv<Type>::type>::value && (etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
53
54#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) \
55 (etl::is_integral< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::value \
56 && (etl::integral_limits< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
57
58namespace etl
59{
60 //*************************************************************************
62 //*************************************************************************
63 class ibase64_decoder : public base64
64 {
65 public:
66
67 typedef etl::span<const unsigned char> span_type;
68 typedef etl::delegate<void(const span_type&)> callback_type;
69
70 //*************************************************************************
72 //*************************************************************************
73 template <typename T>
74 ETL_CONSTEXPR14 bool decode(T value)
75 {
76 ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral");
77
78 push_to_input_buffer(value);
79
80 if (input_buffer_is_full())
81 {
82 if (decode_block())
83 {
84 if (callback.is_valid())
85 {
86 if (output_buffer_is_full())
87 {
88 callback(span());
89 reset_output_buffer();
90 }
91 }
92 }
93
94 reset_input_buffer();
95 }
96
97 return !error();
98 }
99
100 //*************************************************************************
102 //*************************************************************************
103 template <typename TInputIterator>
104 ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, TInputIterator input_end)
105 {
106 ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
107
108 while (input_begin != input_end)
109 {
110 if (!decode(*input_begin++))
111 {
112 return false;
113 }
114 }
115
116 return true;
117 }
118
119 //*************************************************************************
121 //*************************************************************************
122 template <typename TInputIterator>
123 ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, size_t input_length)
124 {
125 ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
126
127 while (input_length-- != 0)
128 {
129 if (!decode(*input_begin++))
130 {
131 return false;
132 }
133 }
134
135 return true;
136 }
137
138 //*************************************************************************
140 //*************************************************************************
141 template <typename TInputIterator>
142 ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, TInputIterator input_end)
143 {
144 return decode(input_begin, input_end) && flush();
145 }
146
147 //*************************************************************************
149 //*************************************************************************
150 template <typename TInputIterator>
151 ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, size_t input_length)
152 {
153 return decode(input_begin, input_length) && flush();
154 }
155
156 //*************************************************************************
158 //*************************************************************************
159 ETL_CONSTEXPR14 bool flush()
160 {
161 // Encode any remaining input data.
162 bool success = decode_block();
163
164 reset_input_buffer();
165
166 if (success)
167 {
168 if (callback.is_valid())
169 {
170 // Send any remaining data.
171 if (size() != 0)
172 {
173 callback(span());
174 }
175
176 // Indicate this was the final block.
177 callback(span_type());
178
179 reset_output_buffer();
180 }
181 }
182
183 padding_received = false;
184
185 return success;
186 }
187
188 //*************************************************************************
190 //*************************************************************************
191 ETL_CONSTEXPR14 void restart()
192 {
193 reset_input_buffer();
194 reset_output_buffer();
195 overflow_detected = false;
196 invalid_data_detected = false;
197 padding_received = false;
198 }
199
200 //*************************************************************************
202 //*************************************************************************
203 ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* begin() const
204 {
205 return p_output_buffer;
206 }
207
208 //*************************************************************************
211 //*************************************************************************
212 ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* end() const
213 {
214 return p_output_buffer + output_buffer_length;
215 }
216
217 //*************************************************************************
219 //*************************************************************************
220 ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cbegin() const
221 {
222 return p_output_buffer;
223 }
224
225 //*************************************************************************
228 //*************************************************************************
229 ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cend() const
230 {
231 return p_output_buffer + output_buffer_length;
232 }
233
234 //*************************************************************************
238 //*************************************************************************
239 ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
240 {
241 return output_buffer_length;
242 }
243
244 //*************************************************************************
246 //*************************************************************************
247 ETL_NODISCARD ETL_CONSTEXPR14 size_t buffer_size() const
248 {
249 return output_buffer_max_size;
250 }
251
252 //*************************************************************************
256 //*************************************************************************
257 ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
258 {
259 return span_type(begin(), end());
260 }
261
262 //*************************************************************************
264 //*************************************************************************
265 ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
266 {
267 return overflow_detected;
268 }
269
270 //*************************************************************************
272 //*************************************************************************
273 ETL_NODISCARD ETL_CONSTEXPR14 bool invalid_data() const
274 {
275 return invalid_data_detected;
276 }
277
278 //*************************************************************************
280 //*************************************************************************
281 ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
282 {
283 return overflow() || invalid_data();
284 }
285
286 protected:
287
288 //*************************************************************************
290 //*************************************************************************
291 ETL_CONSTEXPR14 ibase64_decoder(const char* encoder_table_, bool use_padding_, unsigned char* p_output_buffer_, size_t ouput_buffer_max_size_,
292 callback_type callback_)
293 : base64(encoder_table_, use_padding_)
294 , input_buffer()
295 , input_buffer_length(0)
296 , p_output_buffer(p_output_buffer_)
297 , output_buffer_length(0)
298 , output_buffer_max_size(ouput_buffer_max_size_)
299 , callback(callback_)
300 , overflow_detected(false)
301 , invalid_data_detected(false)
302 , padding_received(false)
303 {
304 }
305
306 //*************************************************************************
308 //*************************************************************************
309 ETL_NODISCARD
310 static ETL_CONSTEXPR14 size_t decoded_size_from_valid_input_length(size_t input_length)
311 {
312 return input_length - (input_length / 4U);
313 }
314
315 private:
316
317 //*************************************************************************
318 // Translates a sextet into an index
319 //*************************************************************************
320 template <typename T>
321 ETL_CONSTEXPR14 uint32_t get_index_from_sextet(T sextet)
322 {
323 const char* encoder_table_end = encoder_table + 64;
324 const char* p_sextet = etl::find(encoder_table, encoder_table_end, static_cast<char>(sextet));
325
326 if (p_sextet != encoder_table_end)
327 {
328 return static_cast<uint32_t>(etl::distance(encoder_table, p_sextet));
329 }
330 else
331 {
332 invalid_data_detected = true;
333 return 0;
334 }
335 }
336
337 //*************************************************************************
339 //*************************************************************************
340 template <typename T>
341 ETL_NODISCARD
342 static
343 ETL_CONSTEXPR14 T padding()
344 {
345 return static_cast<T>('=');
346 }
347
348 //*************************************************************************
350 //*************************************************************************
351 ETL_CONSTEXPR14 bool decode_block()
352 {
353 switch (input_buffer_length)
354 {
355 // Only triggered on call to flush().
356 case 2:
357 {
358 uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 6);
359 sextets = sextets | (get_index_from_sextet(input_buffer[1]));
360 push_to_output_buffer((sextets >> 4) & 0xFF);
361 break;
362 }
363
364 // Only triggered on call to flush().
365 case 3:
366 {
367 uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 12);
368 sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 6);
369 sextets = sextets | (get_index_from_sextet(input_buffer[2]));
370 push_to_output_buffer((sextets >> 10) & 0xFF);
371 push_to_output_buffer((sextets >> 2) & 0xFF);
372 break;
373 }
374
375 // Only triggered on call to decode().
376 case 4:
377 {
378 // Read in four sextets
379 uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 18);
380 sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 12);
381 sextets = sextets | (get_index_from_sextet(input_buffer[2]) << 6);
382 sextets = sextets | (get_index_from_sextet(input_buffer[3]));
383
384 // Write out three octets
385 push_to_output_buffer((sextets >> 16) & 0xFF);
386 push_to_output_buffer((sextets >> 8) & 0xFF);
387 push_to_output_buffer((sextets >> 0) & 0xFF);
388 break;
389 }
390
391 default:
392 {
393 break;
394 }
395 }
396
397 ETL_ASSERT(!invalid_data_detected, ETL_ERROR(etl::base64_invalid_data));
398 ETL_ASSERT(!overflow_detected, ETL_ERROR(etl::base64_overflow));
399
400 return (!invalid_data_detected && !overflow_detected);
401 }
402
403 //*************************************************************************
404 // Push to the output buffer.
405 //*************************************************************************
406 ETL_CONSTEXPR14 void push_to_output_buffer(unsigned char c)
407 {
408 if (output_buffer_length < output_buffer_max_size)
409 {
410 p_output_buffer[output_buffer_length++] = c;
411 }
412 else
413 {
414 overflow_detected = true;
415 }
416 }
417
418 //*************************************************************************
419 //
420 //*************************************************************************
421 ETL_CONSTEXPR14 bool output_buffer_is_full() const
422 {
423 return output_buffer_length == output_buffer_max_size;
424 }
425
426 //*************************************************************************
427 //
428 //*************************************************************************
429 ETL_CONSTEXPR14 bool output_buffer_is_empty() const
430 {
431 return output_buffer_length == 0;
432 }
433
434 //*************************************************************************
435 //
436 //*************************************************************************
437 ETL_CONSTEXPR14 void reset_output_buffer()
438 {
439 output_buffer_length = 0;
440 }
441
442 //*************************************************************************
443 // Push to the input buffer.
444 //*************************************************************************
445 template <typename T>
446 ETL_CONSTEXPR14 void push_to_input_buffer(T value)
447 {
448 if (value == padding<T>())
449 {
450 padding_received = true;
451 }
452 else
453 {
454 if (padding_received)
455 {
456 ETL_ASSERT_FAIL(ETL_ERROR(etl::base64_invalid_data));
457 invalid_data_detected = true;
458 }
459 else
460 {
461 input_buffer[input_buffer_length++] = static_cast<char>(value);
462 }
463 }
464 }
465
466 //*************************************************************************
467 //
468 //*************************************************************************
469 ETL_CONSTEXPR14 bool input_buffer_is_full() const
470 {
471 return input_buffer_length == 4U;
472 }
473
474 //*************************************************************************
475 //
476 //*************************************************************************
477 ETL_CONSTEXPR14 void reset_input_buffer()
478 {
479 input_buffer_length = 0;
480 }
481
482 char input_buffer[4];
483 size_t input_buffer_length;
484
485 unsigned char* p_output_buffer;
486 size_t output_buffer_length;
487 const size_t output_buffer_max_size;
488
489 callback_type callback;
490
491 bool overflow_detected;
492 bool invalid_data_detected;
493 bool padding_received;
494 };
495
496 //*************************************************************************
498 //*************************************************************************
499 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
501 {
502 public:
503
504 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
505
506 //*************************************************************************
508 //*************************************************************************
509 ETL_CONSTEXPR14 base64_rfc2152_decoder()
510 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
511 , output_buffer()
512 {
513 }
514
515 //*************************************************************************
517 //*************************************************************************
518 ETL_CONSTEXPR14 base64_rfc2152_decoder(callback_type callback_)
519 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
520 , output_buffer()
521 {
522 }
523
524 //*************************************************************************
526 //*************************************************************************
527 ETL_NODISCARD
528 static
529 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
530 {
532 }
533
534 private:
535
537 unsigned char output_buffer[Buffer_Size];
538 };
539
540 //*************************************************************************
542 //*************************************************************************
543 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
545 {
546 public:
547
548 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
549
550 //*************************************************************************
552 //*************************************************************************
553 ETL_CONSTEXPR14 base64_rfc3501_decoder()
554 : ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
555 , output_buffer()
556 {
557 }
558
559 //*************************************************************************
561 //*************************************************************************
562 ETL_CONSTEXPR14 base64_rfc3501_decoder(callback_type callback_)
563 : ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
564 , output_buffer()
565 {
566 }
567
568 //*************************************************************************
570 //*************************************************************************
571 ETL_NODISCARD
572 static
573 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
574 {
576 }
577
578 private:
579
581 unsigned char output_buffer[Buffer_Size];
582 };
583
584 //*************************************************************************
586 //*************************************************************************
587 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
589 {
590 public:
591
592 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
593
594 //*************************************************************************
596 //*************************************************************************
597 ETL_CONSTEXPR14 base64_rfc4648_decoder()
598 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
599 , output_buffer()
600 {
601 }
602
603 //*************************************************************************
605 //*************************************************************************
606 ETL_CONSTEXPR14 base64_rfc4648_decoder(callback_type callback_)
607 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
608 , output_buffer()
609 {
610 }
611
612 //*************************************************************************
614 //*************************************************************************
615 ETL_NODISCARD
616 static
617 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
618 {
620 }
621
622 private:
623
625 unsigned char output_buffer[Buffer_Size];
626 };
627
628 //*************************************************************************
630 //*************************************************************************
631 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
633 {
634 public:
635
636 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
637
638 //*************************************************************************
640 //*************************************************************************
642 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
643 , output_buffer()
644 {
645 }
646
647 //*************************************************************************
649 //*************************************************************************
650 ETL_CONSTEXPR14 base64_rfc4648_padding_decoder(callback_type callback_)
651 : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
652 , output_buffer()
653 {
654 }
655
656 //*************************************************************************
658 //*************************************************************************
659 ETL_NODISCARD
660 static
661 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
662 {
664 }
665
666 private:
667
669 unsigned char output_buffer[Buffer_Size];
670 };
671
672 //*************************************************************************
674 //*************************************************************************
675 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
677 {
678 public:
679
680 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
681
682 //*************************************************************************
684 //*************************************************************************
686 : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
687 , output_buffer()
688 {
689 }
690
691 //*************************************************************************
693 //*************************************************************************
694 ETL_CONSTEXPR14 base64_rfc4648_url_decoder(callback_type callback_)
695 : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
696 , output_buffer()
697 {
698 }
699
700 //*************************************************************************
702 //*************************************************************************
703 ETL_NODISCARD
704 static
705 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
706 {
708 }
709
710 private:
711
713 unsigned char output_buffer[Buffer_Size];
714 };
715
716 //*************************************************************************
718 //*************************************************************************
719 template <size_t Buffer_Size = etl::base64::Min_Decode_Buffer_Size>
721 {
722 public:
723
724 ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size");
725
726 //*************************************************************************
728 //*************************************************************************
730 : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
731 , output_buffer()
732 {
733 }
734
735 //*************************************************************************
737 //*************************************************************************
738 ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder(callback_type callback_)
739 : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
740 , output_buffer()
741 {
742 }
743
744 //*************************************************************************
746 //*************************************************************************
747 ETL_NODISCARD
748 static
749 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
750 {
752 }
753
754 private:
755
757 unsigned char output_buffer[Buffer_Size];
758 };
759} // namespace etl
760
761#undef ETL_IS_TYPE_8_BIT_INTEGRAL
762#undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL
763
764#endif
ETL_CONSTEXPR14 base64_rfc2152_decoder()
Base64 RFC-2152 constructor.
Definition base64_decoder.h:509
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:529
ETL_CONSTEXPR14 base64_rfc2152_decoder(callback_type callback_)
Base64 RFC-2152 constructor.
Definition base64_decoder.h:518
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:573
ETL_CONSTEXPR14 base64_rfc3501_decoder()
Base64 RFC-3501 constructor.
Definition base64_decoder.h:553
ETL_CONSTEXPR14 base64_rfc3501_decoder(callback_type callback_)
Base64 RFC-3501 constructor.
Definition base64_decoder.h:562
ETL_CONSTEXPR14 base64_rfc4648_decoder(callback_type callback_)
Base64 RFC-4648 constructor.
Definition base64_decoder.h:606
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:617
ETL_CONSTEXPR14 base64_rfc4648_decoder()
Base64 RFC-4648 constructor.
Definition base64_decoder.h:597
ETL_CONSTEXPR14 base64_rfc4648_padding_decoder(callback_type callback_)
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:650
ETL_CONSTEXPR14 base64_rfc4648_padding_decoder()
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:641
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:661
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:705
ETL_CONSTEXPR14 base64_rfc4648_url_decoder()
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:685
ETL_CONSTEXPR14 base64_rfc4648_url_decoder(callback_type callback_)
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:694
ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder()
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:729
static ETL_NODISCARD ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
Calculate the required output encode buffer size.
Definition base64_decoder.h:749
ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder(callback_type callback_)
Base64 RFC-4648-Padding constructor.
Definition base64_decoder.h:738
Common Base64 definitions.
Definition base64.h:112
Declaration.
Definition delegate_cpp03.h:191
ETL_NODISCARD ETL_CONSTEXPR14 size_t buffer_size() const
Returns the maximum size of the output buffer.
Definition base64_decoder.h:247
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char * end() const
Definition base64_decoder.h:212
ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, size_t input_length)
Decode from Base64.
Definition base64_decoder.h:123
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char * cbegin() const
Returns the beginning of the output buffer.
Definition base64_decoder.h:220
ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
Definition base64_decoder.h:257
ETL_CONSTEXPR14 ibase64_decoder(const char *encoder_table_, bool use_padding_, unsigned char *p_output_buffer_, size_t ouput_buffer_max_size_, callback_type callback_)
Constructor.
Definition base64_decoder.h:291
ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
Definition base64_decoder.h:239
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char * cend() const
Definition base64_decoder.h:229
ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, size_t input_length)
Decode from Base64.
Definition base64_decoder.h:151
ETL_CONSTEXPR14 bool flush()
Flush any remaining data to the output.
Definition base64_decoder.h:159
static ETL_NODISCARD ETL_CONSTEXPR14 size_t decoded_size_from_valid_input_length(size_t input_length)
Calculates the minimum buffer size required to decode from Base64.
Definition base64_decoder.h:310
ETL_CONSTEXPR14 bool decode(T value)
Decode to Base64.
Definition base64_decoder.h:74
ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
Returns true if an error was detected.
Definition base64_decoder.h:281
ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
Returns true if the output buffer has overflowed.
Definition base64_decoder.h:265
ETL_CONSTEXPR14 void restart()
Reset the encoder.
Definition base64_decoder.h:191
ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, TInputIterator input_end)
Decode from Base64.
Definition base64_decoder.h:142
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char * begin() const
Returns the beginning of the output buffer.
Definition base64_decoder.h:203
ETL_NODISCARD ETL_CONSTEXPR14 bool invalid_data() const
Returns true if an invalid character was detected.
Definition base64_decoder.h:273
ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, TInputIterator input_end)
Decode from Base64.
Definition base64_decoder.h:104
Span - Fixed Extent.
Definition span.h:208
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
bitset_ext
Definition absolute.h:40
Definition base64.h:142