2749 {
2750 typedef typename OutputBuffer::value_type output_value_type;
2751 static_assert(std::is_same_v<output_value_type, char> || std::is_same_v<output_value_type, signed char> ||
2752 std::is_same_v<output_value_type, unsigned char> || std::is_same_v<output_value_type, std::byte>);
2753 if (base64Text.empty())
2754 {
2755 return OutputBuffer();
2756 }
2757
2758 if ((base64Text.size() & 3) != 0)
2759 {
2760 throw std::runtime_error{"Invalid base64 encoded data - Size not divisible by 4"};
2761 }
2762
2763 size_t const numPadding = std::count(base64Text.rbegin(), base64Text.rbegin() + 4, '=');
2764 if (numPadding > 2)
2765 {
2766 throw std::runtime_error{"Invalid base64 encoded data - Found more than 2 padding signs"};
2767 }
2768
2769 size_t const decodedsize = (base64Text.size() * 3 >> 2) - numPadding;
2770 OutputBuffer decoded(decodedsize, '.');
2771
2772 uint8_t const* bytes = reinterpret_cast<uint8_t const*>(&base64Text[0]);
2773 char* currDecoding = reinterpret_cast<char*>(&decoded[0]);
2774
2775 for (size_t i = (base64Text.size() >> 2) - (numPadding != 0); i; --i)
2776 {
2777 uint8_t const t1 = *bytes++;
2778 uint8_t const t2 = *bytes++;
2779 uint8_t const t3 = *bytes++;
2780 uint8_t const t4 = *bytes++;
2781
2782 uint32_t const d1 = detail::decode_table_0[t1];
2783 uint32_t const d2 = detail::decode_table_1[t2];
2784 uint32_t const d3 = detail::decode_table_2[t3];
2785 uint32_t const d4 = detail::decode_table_3[t4];
2786
2787 uint32_t const temp = d1 | d2 | d3 | d4;
2788
2790 {
2791 throw std::runtime_error{"Invalid base64 encoded data - Invalid character"};
2792 }
2793
2794
2795
2796
2798
2799 *currDecoding++ = tempBytes[detail::decidx0];
2800 *currDecoding++ = tempBytes[detail::decidx1];
2801 *currDecoding++ = tempBytes[detail::decidx2];
2802 }
2803
2804 switch (numPadding)
2805 {
2806 case 0:
2807 {
2808 break;
2809 }
2810 case 1:
2811 {
2812 uint8_t const t1 = *bytes++;
2813 uint8_t const t2 = *bytes++;
2814 uint8_t const t3 = *bytes++;
2815
2816 uint32_t const d1 = detail::decode_table_0[t1];
2817 uint32_t const d2 = detail::decode_table_1[t2];
2818 uint32_t const d3 = detail::decode_table_2[t3];
2819
2820 uint32_t const temp = d1 | d2 | d3;
2821
2823 {
2824 throw std::runtime_error{"Invalid base64 encoded data - Invalid character"};
2825 }
2826
2827
2828
2829
2831 *currDecoding++ = tempBytes[detail::decidx0];
2832 *currDecoding++ = tempBytes[detail::decidx1];
2833 break;
2834 }
2835 case 2:
2836 {
2837 uint8_t const t1 = *bytes++;
2838 uint8_t const t2 = *bytes++;
2839
2840 uint32_t const d1 = detail::decode_table_0[t1];
2841 uint32_t const d2 = detail::decode_table_1[t2];
2842
2843 uint32_t const temp = d1 | d2;
2844
2846 {
2847 throw std::runtime_error{"Invalid base64 encoded data - Invalid character"};
2848 }
2849
2851 *currDecoding++ = tempBytes[detail::decidx0];
2852 break;
2853 }
2854 default:
2855 {
2856 throw std::runtime_error{"Invalid base64 encoded data - Invalid padding number"};
2857 }
2858 }
2859
2860 return decoded;
2861 }
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable_v< From > &&std::is_trivially_copyable_v< To >, To > bit_cast(const From &src) noexcept
constexpr uint32_t bad_char