-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.hpp
More file actions
892 lines (779 loc) · 42.1 KB
/
Copy pathdecode.hpp
File metadata and controls
892 lines (779 loc) · 42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
#pragma once
#pragma push_macro("BIZWEN_EXPORT")
#undef BIZWEN_EXPORT
#if !defined(BIZWEN_MODULE)
#define BIZWEN_EXPORT
#include <array>
#include <cassert>
#include <concepts>
#include <cstring>
#include <iterator>
#include <ranges>
#include <type_traits>
#include <utility>
#include "./common.hpp"
#else
#define BIZWEN_EXPORT export
#endif
namespace bizwen
{
namespace decode_impl
{
namespace table
{
#if defined(BIZWEN_PREDEFINED_LOOKUP_TABLE)
inline constexpr auto base64 = std::array<char8_t, 256>{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 62, 0xFF, 0xFF, 0xFF, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
#else
namespace detail
{
inline constexpr char8_t invalid = static_cast<char8_t>(0xFF);
enum class alpha_case
{
upper,
lower,
mixed,
};
inline constexpr bool is_ascii_upper(char8_t c) noexcept
{
return c >= u8'A' && c <= u8'Z';
}
inline constexpr bool is_ascii_lower(char8_t c) noexcept
{
return c >= u8'a' && c <= u8'z';
}
inline constexpr char8_t ascii_to_lower(char8_t c) noexcept
{
if (is_ascii_upper(c))
return c + static_cast<char8_t>(32);
return c;
}
inline constexpr char8_t ascii_flip_alpha_case(char8_t c) noexcept
{
if (is_ascii_upper(c))
return c + static_cast<char8_t>(32);
if (is_ascii_lower(c))
return c - static_cast<char8_t>(32);
return c;
}
template <std::size_t N>
inline consteval std::array<char8_t, 256> make_decode_table(char8_t const (&alphabet)[N], alpha_case mode) noexcept
{
std::array<char8_t, 256> out{};
out.fill(invalid);
for (std::size_t i = 0; i != N - 1; ++i)
{
auto const value = static_cast<char8_t>(i);
auto const c = alphabet[i];
if (mode == alpha_case::upper)
{
out[c] = value;
}
else if (mode == alpha_case::lower)
{
out[ascii_to_lower(c)] = value;
}
else // alpha_case::mixed
{
out[c] = value;
out[ascii_flip_alpha_case(c)] = value;
}
}
return out;
}
} // namespace detail
inline constexpr auto base64 = detail::make_decode_table(
u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", detail::alpha_case::upper);
inline constexpr auto base64_url = detail::make_decode_table(
u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", detail::alpha_case::upper);
inline constexpr auto base32 =
detail::make_decode_table(u8"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", detail::alpha_case::upper);
inline constexpr auto base32_lower =
detail::make_decode_table(u8"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", detail::alpha_case::lower);
inline constexpr auto base32_mixed =
detail::make_decode_table(u8"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", detail::alpha_case::mixed);
inline constexpr auto base32_hex =
detail::make_decode_table(u8"0123456789ABCDEFGHIJKLMNOPQRSTUV", detail::alpha_case::upper);
inline constexpr auto base32_hex_lower =
detail::make_decode_table(u8"0123456789ABCDEFGHIJKLMNOPQRSTUV", detail::alpha_case::lower);
inline constexpr auto base32_hex_mixed =
detail::make_decode_table(u8"0123456789ABCDEFGHIJKLMNOPQRSTUV", detail::alpha_case::mixed);
inline constexpr auto base32_crockford =
detail::make_decode_table(u8"0123456789ABCDEFGHJKMNPQRSTVWXYZ", detail::alpha_case::upper);
inline constexpr auto base32_crockford_lower =
detail::make_decode_table(u8"0123456789ABCDEFGHJKMNPQRSTVWXYZ", detail::alpha_case::lower);
inline constexpr auto base32_crockford_mixed =
detail::make_decode_table(u8"0123456789ABCDEFGHJKMNPQRSTVWXYZ", detail::alpha_case::mixed);
inline constexpr auto base16 = detail::make_decode_table(u8"0123456789ABCDEF", detail::alpha_case::upper);
inline constexpr auto base16_lower = detail::make_decode_table(u8"0123456789ABCDEF", detail::alpha_case::lower);
inline constexpr auto base16_mixed = detail::make_decode_table(u8"0123456789ABCDEF", detail::alpha_case::mixed);
#endif
} // namespace table
using table_ref = std::add_lvalue_reference_t<decltype(table::base64)>;
inline constexpr table_ref get_table(rfc4648_kind kind) noexcept
{
if (kind == rfc4648_kind::base64)
return table::base64;
if (kind == rfc4648_kind::base64_url)
return table::base64_url;
if (kind == rfc4648_kind::base32)
return table::base32;
if (kind == rfc4648_kind::base32_lower)
return table::base32_lower;
if (kind == rfc4648_kind::base32_mixed)
return table::base32_mixed;
if (kind == rfc4648_kind::base32_hex)
return table::base32_hex;
if (kind == rfc4648_kind::base32_hex_lower)
return table::base32_hex_lower;
if (kind == rfc4648_kind::base32_hex_mixed)
return table::base32_hex_mixed;
if (kind == rfc4648_kind::base32_crockford)
return table::base32_crockford;
if (kind == rfc4648_kind::base32_crockford_lower)
return table::base32_crockford_lower;
if (kind == rfc4648_kind::base32_crockford_mixed)
return table::base32_crockford_mixed;
if (kind == rfc4648_kind::base16)
return table::base16;
if (kind == rfc4648_kind::base16_lower)
return table::base16_lower;
if (kind == rfc4648_kind::base16_mixed)
return table::base16_mixed;
assert(false);
std::unreachable();
}
template <typename T>
inline constexpr bool valid_stage1(T t) noexcept
{
using u = std::make_unsigned_t<T>;
if (sizeof(T) == 1)
return true;
else
return !(u(t) & ~u(0xFF));
}
inline constexpr bool valid_stage2(unsigned char t) noexcept
{
return t != 0xFF;
}
template <typename T>
inline constexpr bool is_valid(T t, unsigned char u) noexcept
{
static_assert(!std::is_same_v<unsigned char, T>);
return valid_stage1(t) && valid_stage2(u);
}
template <typename T>
inline constexpr unsigned char decode_single(T t, table_ref table) noexcept
{
return table[static_cast<unsigned char>(t)];
}
template <typename Out>
void check_value_write(Out &&out, unsigned char value)
{
if constexpr (std::indirectly_writable<Out, unsigned char>)
*out = value;
else if constexpr (std::indirectly_writable<Out, char>)
*out = static_cast<char>(value);
else if constexpr (std::indirectly_writable<Out, std::byte>)
*out = static_cast<std::byte>(value);
else
static_assert(false,
"Output iterator cannot be used to write values of type char, unsigned char, or std::byte.");
}
struct decode_status_b64_b32
{
// base64
// 1 2 3 4
// XXXXXX XXXXXX XXXXXX XXXXXX
// XXXXXX XX
// XXXX XXXX
// XX XXXXXX
// base32
// 1 2 3 4 5 6 7 8
// XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX
// XXXXX XXX
// XX XXXXX X
// XXXX XXXX
// X XXXXX XX
// XXX XXXXX
alignas(int) unsigned char sig_{}; // 0 - 4, 0 - 8
alignas(int) unsigned char buf_;
// If sig is not 0 at the end of decoding, then buf_ must be 0 and discarded.
template <typename C, typename Out>
bool write_b64(C c, Out &first, table_ref table)
{
auto res = decode_single(c, table);
if (!is_valid(c, res))
return false;
++sig_;
if (sig_ == 1)
{
buf_ = res << 2;
}
else if (sig_ == 2)
{
check_value_write(first, buf_ | res >> 4);
++first;
buf_ = res << 4;
}
else if (sig_ == 3)
{
check_value_write(first, buf_ | (res >> 2));
++first;
buf_ = res << 6;
}
else if (sig_ == 4)
{
check_value_write(first, buf_ | res);
++first;
// NB: reset sig
sig_ = 0;
}
else
{
std::unreachable();
}
return true;
}
template <typename In>
void eat_equal_sign_b64(In &begin, In &end) noexcept
{
static_assert(std::is_pointer_v<In>);
if (sig_ == 3)
{
if (begin != end && *begin == '=')
++begin;
}
else if (sig_ == 2)
{
if (begin != end && *begin == '=')
++begin;
if (begin != end && *begin == '=')
++begin;
}
}
template <typename C, typename Out>
bool write_b32(C c, Out &first, table_ref table)
{
auto res = decode_single(c, table);
if (!is_valid(c, res))
return false;
++sig_;
if (sig_ == 1)
{
buf_ = res << 3;
}
else if (sig_ == 2)
{
check_value_write(first, buf_ | res >> 2);
++first;
buf_ = res << 6;
}
else if (sig_ == 3)
{
buf_ |= res << 1;
}
else if (sig_ == 4)
{
check_value_write(first, buf_ | res >> 4);
++first;
buf_ = res << 4;
}
else if (sig_ == 5)
{
check_value_write(first, buf_ | res >> 1);
++first;
buf_ = res << 7;
}
else if (sig_ == 6)
{
buf_ |= res << 2;
}
else if (sig_ == 7)
{
check_value_write(first, buf_ | res >> 3);
++first;
buf_ = res << 5;
}
else if (sig_ == 8)
{
check_value_write(first, buf_ | res);
++first;
// NB: reset sig
sig_ = 0;
}
else
{
std::unreachable();
}
return true;
}
template <typename In>
void eat_equal_sign_b32(In &begin, In &end) noexcept
{
static_assert(std::is_pointer_v<In>);
if ((sig_ == 2) | (sig_ == 4) | (sig_ == 5) | (sig_ == 7))
{
for (std::size_t i{}; i != (8 - sig_); ++i)
{
if (begin != end)
{
if (*begin == '=')
++begin;
else
return;
}
else
{
return;
}
}
}
}
};
template <typename In, typename Out>
inline constexpr In decode_impl_b32(In begin, In end, Out &first, table_ref table, bool padding)
{
static_assert(std::is_pointer_v<In>);
decode_status_b64_b32 status{};
for (; begin != end; ++begin)
{
if (!status.write_b32(*begin, first, table))
break;
}
if (padding)
{
status.eat_equal_sign_b32(begin, end);
}
return begin;
}
template <typename In, typename Out>
inline constexpr In decode_impl_b64(In begin, In end, Out &first, table_ref table, bool padding)
{
static_assert(std::is_pointer_v<In>);
decode_status_b64_b32 status{};
for (; begin != end; ++begin)
{
if (!status.write_b64(*begin, first, table))
break;
}
if (padding)
{
status.eat_equal_sign_b64(begin, end);
}
return begin;
}
template <typename In, typename Out>
inline constexpr In decode_impl_b64_ctx(detail::sig_ref sig, detail::buf_ref buf, In begin, In end, Out &first,
table_ref table)
{
static_assert(std::is_pointer_v<In>);
decode_status_b64_b32 status{sig, buf[0]};
for (; begin != end; ++begin)
{
if (!status.write_b64(*begin, first, table))
break;
}
sig = status.sig_;
buf[0] = status.buf_;
return begin;
}
template <typename In, typename Out>
inline constexpr In decode_impl_b32_ctx(detail::sig_ref sig, detail::buf_ref buf, In begin, In end, Out &first,
table_ref table)
{
static_assert(std::is_pointer_v<In>);
decode_status_b64_b32 status{sig, buf[0]};
for (; begin != end; ++begin)
{
if (!status.write_b32(*begin, first, table))
break;
}
sig = status.sig_;
buf[0] = status.buf_;
return begin;
}
template <typename In>
inline constexpr void decode_impl_b64_ctx(detail::sig_ref sig, detail::buf_ref buf, In &begin, In &end,
bool padding) noexcept
{
auto sig_ = sig;
sig = 0;
if (padding)
{
decode_status_b64_b32 status{sig_, buf[0]};
status.eat_equal_sign_b64(begin, end);
}
}
template <typename In>
inline constexpr void decode_impl_b32_ctx(detail::sig_ref sig, detail::buf_ref buf, In &begin, In &end,
bool padding) noexcept
{
auto sig_ = sig;
sig = 0;
if (padding)
{
decode_status_b64_b32 status{sig_, buf[0]};
status.eat_equal_sign_b32(begin, end);
}
}
template <typename In, typename Out>
inline constexpr In decode_impl_b16(In begin, In end, Out &first, table_ref table)
{
static_assert(std::is_pointer_v<In>);
while (end - begin > 1)
{
auto c0 = *begin;
auto res0 = decode_single(c0, table);
if (!is_valid(c0, res0))
return begin;
++begin;
auto c1 = *begin;
auto res1 = decode_single(c1, table);
if (!is_valid(c1, res1))
return begin;
++begin;
check_value_write(first, (res0 << 4) | res1);
++first;
}
if (end != begin)
{
auto c = *begin;
auto res = decode_single(c, table);
if (!is_valid(c, res))
return begin;
++begin;
check_value_write(first, res << 4);
++first;
}
return begin;
}
template <typename In, typename Out>
inline constexpr In decode_impl_b16_ctx(detail::sig_ref sig, detail::buf_ref buf, In begin, In end, Out &first,
table_ref table)
{
static_assert(std::is_pointer_v<In>);
for (; begin != end; ++begin)
{
auto c = *begin;
auto res = decode_single(c, table);
if (!is_valid(c, res))
break;
++sig;
if (sig == 1)
{
buf[0] = res << 4;
sig = 1;
}
else if (sig == 2)
{
check_value_write(first, buf[0] | res);
++first;
sig = 0;
}
else
{
std::unreachable();
}
}
return begin;
}
struct rfc4648_decode_fn
{
template <typename In, typename End, typename Out>
static inline constexpr rfc4648_decode_result<In, Out> operator()(In begin, End end, Out first,
rfc4648_kind kind = rfc4648_kind::base64,
bool padding = true)
{
using in_char = std::iterator_traits<In>::value_type;
static_assert(std::contiguous_iterator<In>);
static_assert(std::sized_sentinel_for<End, In>);
static_assert(std::is_same_v<in_char, char> || std::is_same_v<in_char, wchar_t> ||
std::is_same_v<in_char, char8_t> || std::is_same_v<in_char, char16_t> ||
std::is_same_v<in_char, char32_t>);
auto begin_ptr = detail::to_address_const(begin);
auto end_ptr = detail::to_address_const(begin + (end - begin));
decltype(begin_ptr) last_ptr = {};
if (detail::get_family(kind) == rfc4648_kind::base64)
last_ptr = decode_impl::decode_impl_b64(begin_ptr, end_ptr, first, decode_impl::get_table(kind), padding);
if (detail::get_family(kind) == rfc4648_kind::base32)
last_ptr = decode_impl::decode_impl_b32(begin_ptr, end_ptr, first, decode_impl::get_table(kind), padding);
;
if (detail::get_family(kind) == rfc4648_kind::base16)
last_ptr = decode_impl::decode_impl_b16(begin_ptr, end_ptr, first, decode_impl::get_table(kind));
;
return {begin + (last_ptr - begin_ptr), std::move(first)};
}
template <typename R, typename Out>
requires std::ranges::contiguous_range<R> && std::ranges::borrowed_range<R>
static inline constexpr auto operator()(R &&r, Out first, rfc4648_kind kind = rfc4648_kind::base64,
bool padding = true)
{
return operator()(std::ranges::begin(r), std::ranges::end(r), first, kind, padding);
}
template <typename In, typename End, typename Out>
static inline constexpr rfc4648_decode_result<In, Out> operator()(rfc4648_context &ctx, In begin, End end, Out first,
rfc4648_kind kind = rfc4648_kind::base64)
{
using in_char = std::iterator_traits<In>::value_type;
static_assert(std::contiguous_iterator<In>);
static_assert(std::sized_sentinel_for<End, In>);
static_assert(std::is_same_v<in_char, char> || std::is_same_v<in_char, wchar_t> ||
std::is_same_v<in_char, char8_t> || std::is_same_v<in_char, char16_t> ||
std::is_same_v<in_char, char32_t>);
auto begin_ptr = detail::to_address_const(begin);
auto end_ptr = detail::to_address_const(begin + (end - begin));
decltype(begin_ptr) last_ptr = {};
if (detail::get_family(kind) == rfc4648_kind::base64)
last_ptr = decode_impl::decode_impl_b64_ctx(ctx.sig_, ctx.buf_, begin_ptr, end_ptr, first,
decode_impl::get_table(kind));
if (detail::get_family(kind) == rfc4648_kind::base32)
last_ptr = decode_impl::decode_impl_b32_ctx(ctx.sig_, ctx.buf_, begin_ptr, end_ptr, first,
decode_impl::get_table(kind));
;
if (detail::get_family(kind) == rfc4648_kind::base16)
last_ptr = decode_impl::decode_impl_b16_ctx(ctx.sig_, ctx.buf_, begin_ptr, end_ptr, first,
decode_impl::get_table(kind));
;
return {begin + (last_ptr - begin_ptr), std::move(first)};
}
template <typename R, typename Out>
requires std::ranges::contiguous_range<R> && std::ranges::borrowed_range<R>
static inline constexpr auto operator()(rfc4648_context &ctx, R &&r, Out first,
rfc4648_kind kind = rfc4648_kind::base64)
{
return operator()(ctx, std::ranges::begin(r), std::ranges::end(r), first, kind);
}
template <typename In, typename End>
static inline constexpr In operator()(rfc4648_context &ctx, In begin, End end,
rfc4648_kind kind = rfc4648_kind::base64, bool padding = true)
{
using in_char = std::iterator_traits<In>::value_type;
static_assert(std::contiguous_iterator<In>);
static_assert(std::sized_sentinel_for<End, In>);
static_assert(std::is_same_v<in_char, char> || std::is_same_v<in_char, wchar_t> ||
std::is_same_v<in_char, char8_t> || std::is_same_v<in_char, char16_t> ||
std::is_same_v<in_char, char32_t>);
auto begin_ptr = detail::to_address_const(begin);
auto end_ptr = detail::to_address_const(begin + (end - begin));
decltype(begin_ptr) last_ptr = begin_ptr;
if (detail::get_family(kind) == rfc4648_kind::base64)
decode_impl::decode_impl_b64_ctx(ctx.sig_, ctx.buf_, last_ptr, end_ptr, padding);
if (detail::get_family(kind) == rfc4648_kind::base32)
decode_impl::decode_impl_b32_ctx(ctx.sig_, ctx.buf_, last_ptr, end_ptr, padding);
// no effect when family is base16 and CHAR_BIT is 8
return {begin + (last_ptr - begin_ptr)};
}
};
} // namespace decode_impl
BIZWEN_EXPORT inline constexpr decode_impl::rfc4648_decode_fn rfc4648_decode;
} // namespace bizwen
#pragma pop_macro("BIZWEN_EXPORT")