MySQL 9.1.0
Source Code Documentation
base64.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_HTTP_BASE64_INCLUDED
27#define MYSQLROUTER_HTTP_BASE64_INCLUDED
28
30
31#include <algorithm> // min
32#include <array>
33#include <cstdint>
34#include <cstring> // strlen
35#include <stdexcept>
36#include <string>
37#include <string_view>
38#include <utility> // index_sequence
39#include <vector>
40
41enum class Base64Endianess { LITTLE, BIG };
42
43namespace mysqlrouter {
44inline const char *begin(const char *const c) { return c; }
45inline const char *end(const char *const c) { return c + strlen(c); }
46inline size_t size(const char *const c) { return strlen(c); }
47} // namespace mysqlrouter
48
49/**
50 * Generic Base64 codec.
51 *
52 * Base64 comes in many flavours:
53 *
54 * - RFC4648 used by HTTP
55 * - crypt
56 * - bcrypt
57 * - pbkdf2 in MCF
58 * - UUencode
59 *
60 * they differ by
61 *
62 * - alphabet
63 * - endianness
64 * - padding
65 *
66 * Base64Impl provides generic encode and decode methods which are parametrized
67 * by Endianness, Padding.
68 *
69 * Parametrization with templates allows to provide:
70 *
71 * - one implementation for all combinations
72 * - without extra runtime overhead as dead code is removed by the compiler
73 *
74 * Endianness
75 * =========
76 *
77 * Little Endian
78 * -------------
79 *
80 * using Alphabet=Crypt
81 *
82 * octet(hex): 55
83 * uint32: ........ ........ 01010101 (LSB)
84 * uint32: ...... ...... ....01 010101 (LSB)
85 * sextet(hex): 1 15
86 * Alphabet: / J
87 *
88 * Out: J/
89 *
90 *
91 * Big Endian
92 * ----------
93 *
94 * using Alphabet=Crypt
95 *
96 * octet(hex): 55
97 * uint32: 01010101 ........ ........ (LSB)
98 * uint32: 010101 01.... ...... ...... (LSB)
99 * sextet(hex): 15 10
100 * Alphabet: J E
101 *
102 * Out: JE
103 *
104 * Padding
105 * =======
106 *
107 * If padding is defined mandatory,
108 *
109 * - at encode() each group of 4 sextets is filled by with the padding
110 * character.
111 * - at decode() input must have padding.
112 *
113 * If padding is not mandatory,
114 *
115 * - at encode() no padding is added.
116 * - at decode() padding is accepted, but not required.
117 */
119 public:
120 /**
121 * type of all alphabet.
122 */
123 using alphabet_type = std::array<char, 64>;
124
125 /**
126 * type of all inverse mappings of alphabets.
127 *
128 * - -1 invalid
129 * - 0-63 position into alphabet
130 */
131 using inverse_alphabet_type = std::array<int8_t, 256>;
132
133 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
134 static std::vector<uint8_t> decode(
135 const std::string &encoded,
136 const inverse_alphabet_type &inverse_alphabet) {
137 std::vector<uint8_t> out((encoded.size() + 3) / 4 * 3);
138
139 constexpr unsigned int shift_pos_0 =
140 endianess == Base64Endianess::BIG ? 16 : 0;
141 constexpr unsigned int shift_pos_1 =
142 endianess == Base64Endianess::BIG ? 8 : 8;
143 constexpr unsigned int shift_pos_2 =
144 endianess == Base64Endianess::BIG ? 0 : 16;
145
146 auto out_it = out.begin();
147 auto data_it = encoded.cbegin();
148 const auto data_end_it = encoded.cend();
149 while (const size_t data_left = std::distance(data_it, data_end_it)) {
150 if (data_left < 2) {
151 throw std::runtime_error("invalid sequence");
152 }
153
154 if (PaddingMandatory && (data_left < 4)) {
155 throw std::runtime_error("missing padding");
156 }
157
158 uint32_t v = 0;
159 bool is_padding = false;
160 const size_t max_rounds = std::min(size_t{4}, data_left);
161 uint32_t sextets = 0;
162 for (size_t cnt = 0; cnt < max_rounds; ++cnt) {
163 const uint8_t b64 = *(data_it++);
164 if (is_padding && b64 != PaddingChar) {
165 throw std::runtime_error("invalid char, expected padding");
166 }
167 const int8_t c = (inverse_alphabet[b64]);
168
169 if (c == -1) {
170 if (data_left <= 4 && cnt >= 2 && b64 == PaddingChar) {
171 // padding is ok at the end
172 is_padding = true;
173 } else {
174 throw std::runtime_error(std::string("invalid char"));
175 }
176 }
177
178 // add new 6 bits
179 if (!is_padding) {
180 if (endianess == Base64Endianess::BIG) {
181 v |= c << (6 * (3 - cnt));
182 } else {
183 v |= c << (6 * cnt);
184 }
185 sextets++;
186 }
187 }
188
189 // 3 * 6bit b64 = 18bits translates to 16bit (2 bits extra)
190 // 2 * 6bit b64 = 12bits translates to 8bit (4 bits extra)
191 //
192 // They must be 0b0 to ensure only one b64 value
193 // maps to one 8bit version and the other way around.
194 //
195 // Example
196 // ------
197 //
198 // WWU= -> Ye -> WWU=
199 //
200 // 0x14
201 // ...... ...... 010100
202 // ........ ........ xx
203 //
204 // WWW= -> Ye -> WWU=
205 //
206 // 0x16
207 // ...... ...... 010110
208 // ........ ........ xx
209 //
210 switch (sextets) {
211 case 2:
212 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_0);
213
214 if (0 != static_cast<uint8_t>(v >> shift_pos_1)) {
215 throw std::runtime_error("unused bits");
216 }
217 break;
218 case 3:
219 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_0);
220 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_1);
221
222 if (0 != static_cast<uint8_t>(v >> shift_pos_2)) {
223 throw std::runtime_error("unused bits");
224 }
225 break;
226 case 4:
227 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_0);
228 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_1);
229 *(out_it++) = static_cast<uint8_t>(v >> shift_pos_2);
230 break;
231 }
232 }
233
234 out.resize(std::distance(out.begin(), out_it));
235
236 return out;
237 }
238
239 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
240 static std::string encode(const std::vector<uint8_t> &data,
241 const alphabet_type &alphabet) {
242 return encode_impl<endianess, PaddingMandatory, PaddingChar>(data,
243 alphabet);
244 }
245
246 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
247 static std::string encode(const std::string &data,
248 const alphabet_type &alphabet) {
249 return encode_impl<endianess, PaddingMandatory, PaddingChar>(data,
250 alphabet);
251 }
252
253 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
254 static std::string encode(const std::string_view &data,
255 const alphabet_type &alphabet) {
256 return encode_impl<endianess, PaddingMandatory, PaddingChar>(data,
257 alphabet);
258 }
259
260 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
261 static std::string encode(const char *data, const alphabet_type &alphabet) {
262 return encode_impl<endianess, PaddingMandatory, PaddingChar>(data,
263 alphabet);
264 }
265
266 private:
267 template <Base64Endianess endianess, bool PaddingMandatory, char PaddingChar,
268 typename T>
269 static std::string encode_impl(const T &data, const alphabet_type &alphabet) {
270 std::string out;
271 using mysqlrouter::begin;
272 using mysqlrouter::end;
273 using mysqlrouter::size;
274 using std::begin;
275 using std::end;
276 using std::size;
277 // ensure we have enough space
278 out.resize((size(data) + 2) / 3 * 4);
279
280 constexpr unsigned int shift_pos_0 =
281 endianess == Base64Endianess::BIG ? 16 : 0;
282 constexpr unsigned int shift_pos_1 =
283 endianess == Base64Endianess::BIG ? 8 : 8;
284 constexpr unsigned int shift_pos_2 =
285 endianess == Base64Endianess::BIG ? 0 : 16;
286
287 auto out_it = out.begin();
288 auto data_it = begin(data);
289 const auto data_end_it = end(data);
290 while (const size_t data_left = std::distance(data_it, data_end_it)) {
291 // consume 3 bytes, if we have them
292 uint32_t v = 0;
293
294 size_t padding_pos = 4; // no padding
295 switch (data_left) {
296 case 1:
297 v |= (*(data_it++)) << shift_pos_0;
298 padding_pos = 2; // out-byte 2 and 3 are padding
299 break;
300 case 2:
301 v |= (static_cast<uint8_t>(*(data_it++))) << shift_pos_0;
302 v |= (static_cast<uint8_t>(*(data_it++))) << shift_pos_1;
303 padding_pos = 3; // out-byte 3 is padding
304 break;
305 default:
306 v |= (static_cast<uint8_t>(*(data_it++))) << shift_pos_0;
307 v |= (static_cast<uint8_t>(*(data_it++))) << shift_pos_1;
308 v |= (static_cast<uint8_t>(*(data_it++))) << shift_pos_2;
309 break;
310 }
311
312 // and base64-encode them
313 size_t cnt;
314 for (cnt = 0; cnt < 4; ++cnt) {
315 if (cnt >= padding_pos) {
316 break;
317 }
318
319 size_t pos;
320 if (endianess == Base64Endianess::BIG) {
321 // take the upper 6 bit and shift left each round
322 pos = (v & (0x3f << (3 * 6))) >> 3 * 6;
323 v <<= 6;
324 } else {
325 // take the lower 6 bit and shift right each round
326 pos = v & 0x3f;
327 v >>= 6;
328 }
329 *(out_it++) = alphabet.at(pos);
330 }
331
332 if (PaddingMandatory) {
333 // apply padding if needed
334 for (; cnt < 4; ++cnt) {
335 *(out_it++) = PaddingChar;
336 }
337 }
338 }
339 out.resize(std::distance(out.begin(), out_it));
340
341 return out;
342 }
343};
344
345namespace Base64Alphabet {
346
347/**
348 * type of all alphabet.
349 */
351
352/**
353 * type of all inverse mappings of alphabets.
354 *
355 * - -1 invalid
356 * - 0-63 position into alphabet
357 */
359
360namespace detail {
361/**
362 * find position of char in alphabet.
363 *
364 * @returns position in alphabet
365 * @retval -1 if not found
366 */
367constexpr int8_t find_pos_of_char(const alphabet_type &v, uint8_t character,
368 size_t v_ndx = 0) {
369 // ensure that -1 and 255 don't overlap
370 static_assert(alphabet_type().size() <= 128,
371 "alphabet MUST less <= 128 chars");
372 return (v_ndx >= v.size() ? -1
373 : (v[v_ndx] == static_cast<char>(character))
374 ? static_cast<uint8_t>(v_ndx)
375 : find_pos_of_char(v, character, v_ndx + 1));
376}
377
378// hand-roll std::make_index_sequence<256> as SunCC 12.6 runs into:
379//
380// Error: Templates nested too deeply (recursively?).
381//
382// for std::make_index_sequence<n> with n > 255
383//
384// see: https://community.oracle.com/thread/4070120
385//
386// There exists a workaround:
387//
388// > The compiler has an undocumented "Q option" (or "Wizard option") that
389// > lets you increase the allowed depth:
390// >
391// > -Qoption ccfe -tmpldepth=N
392// > -W0,-tmpldepth=N
393//
394// but here we go the hand-rolled version of what std::make_index_sequence<256>
395// would have generated instead.
396
397using ndx_256 = std::index_sequence<
398 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
399 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
400 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
401 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
402 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
403 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
404 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
405 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
406 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
407 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
408 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
409 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
410 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
411 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
412 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
413 248, 249, 250, 251, 252, 253, 254, 255>;
414
415/**
416 * build inverse-alphabet.
417 *
418 * calls find_pos_by_char() for each element of ndx_256
419 *
420 * based on C++11 parameter pack.
421 */
422template <std::size_t... I>
424 std::index_sequence<I...>) {
425 return {{find_pos_of_char(v, I)...}};
426}
427
428/**
429 * inverse
430 */
432 return make_inverse_array(v, ndx_256{});
433}
434} // namespace detail
435
436class Base64 {
437 public:
439 {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0x00
440 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', //
441 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 0x10
442 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', //
443 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 0x20
444 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', //
445 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 0x30
446 '4', '5', '6', '7', '8', '9', '+', '/'}};
447
450};
451
453 public:
455 {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0x00
456 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', //
457 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 0x10
458 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', //
459 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 0x20
460 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', //
461 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 0x30
462 '4', '5', '6', '7', '8', '9', '-', '_'}};
463
466};
467
468/**
469 * Base64 alphabet for MCF.
470 *
471 * same as Base64 from RFC4648, but different altchars to fit the needs of MCF
472 *
473 * altchars
474 * : . and /
475 *
476 * paddingchar
477 * : =
478 *
479 * padding mandatory
480 * : no
481 */
482class Mcf {
483 public:
485 {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0x00
486 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', //
487 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 0x10
488 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', //
489 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 0x20
490 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', //
491 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 0x30
492 '4', '5', '6', '7', '8', '9', '.', '/'}};
493
496};
497
498class Crypt {
499 public:
501 {'.', '/', '0', '1', '2', '3', '4', '5', // 0x00
502 '6', '7', '8', '9', 'A', 'B', 'C', 'D', //
503 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', // 0x10
504 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', //
505 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', // 0x20
506 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', //
507 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', // 0x30
508 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}};
509
512};
513
514class Bcrypt {
515 public:
517 {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F', // 0x00
518 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', //
519 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', // 0x10
520 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', //
521 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', // 0x20
522 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', //
523 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', // 0x30
524 '2', '3', '4', '5', '6', '7', '8', '9'}};
525
528};
529
530class Uuencode {
531 public:
533 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, // 0x00
534 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
535 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x10
536 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
537 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // 0x20
538 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
539 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // 0x30
540 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
541 }};
542
545};
546} // namespace Base64Alphabet
547
548/**
549 * Base64 codec base class.
550 */
551template <class Alphabet, Base64Endianess E, bool PaddingMandatory,
552 char PaddingChar>
554 public:
555 /**
556 * decode a base64 encoded string to binary.
557 *
558 * @pre encoded only contains alphabet
559 *
560 * @throws std::runtime_error if preconditions are not met
561 * @returns binary representation
562 */
563 static std::vector<uint8_t> decode(const std::string &encoded) {
564 return Base64Impl::decode<E, PaddingMandatory, PaddingChar>(
565 encoded, Alphabet::inverse_alphabet);
566 }
567
568 /**
569 * encode binary to base64.
570 */
571 static std::string encode(const std::vector<uint8_t> &decoded) {
572 return Base64Impl::encode<E, PaddingMandatory, PaddingChar>(
573 decoded, Alphabet::alphabet);
574 }
575
576 static std::string encode(const std::string_view &decoded) {
577 return Base64Impl::encode<E, PaddingMandatory, PaddingChar>(
578 decoded, Alphabet::alphabet);
579 }
580};
581
582/**
583 * 'base64' alphabet from RFC4648.
584 *
585 * also used by:
586 *
587 * - uuencode-base64
588 * - data URI scheme (RFC2397)
589 *
590 * alphabet
591 * : `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
592 *
593 * padding mandatory
594 * : yes, with =
595 */
596using Base64 =
598
599/**
600 * 'base64url' URL and Filename-safe Base64 alphabet from RFC4648.
601 *
602 * '+' and '/' in 'base64' have special meaning in URLs and would need
603 * to be URL-encoded.
604 *
605 * alphabet
606 * : `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`
607 *
608 * padding mandatory
609 * : yes, with =
610 */
613
614/**
615 * Base64 alphabet for MCF's pbkdf2 methods.
616 *
617 * alphabet
618 * : `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./`
619 *
620 * padding mandatory
621 * : no
622 */
625
626/**
627 * Radix64 for crypt (little-endian).
628 *
629 * alphabet
630 * : `./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
631 *
632 * padding mandatory
633 * : no
634 */
637
638/**
639 * Radix64 for crypt (big-endian).
640 *
641 * @see Radix64Crypt
642 */
645
646/**
647 * Radix64 for bcrypt.
648 *
649 * alphabet
650 * : `./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`
651 *
652 * padding mandatory
653 * : no
654 */
657
658/**
659 * Radix64 for traditional Uuencode.
660 *
661 * alphabet
662 * : 0x32...0x95
663 *
664 * padding mandatory
665 * : yes, with accent
666 */
669
670#endif
Definition: base64.h:452
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:464
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:454
Definition: base64.h:436
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:438
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:448
Definition: base64.h:514
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:516
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:526
Definition: base64.h:498
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:500
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:510
Base64 alphabet for MCF.
Definition: base64.h:482
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:484
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:494
Definition: base64.h:530
static constexpr alphabet_type HTTP_COMMON_EXPORT alphabet
Definition: base64.h:532
static constexpr inverse_alphabet_type HTTP_COMMON_EXPORT inverse_alphabet
Definition: base64.h:543
Base64 codec base class.
Definition: base64.h:553
static std::string encode(const std::string_view &decoded)
Definition: base64.h:576
static std::string encode(const std::vector< uint8_t > &decoded)
encode binary to base64.
Definition: base64.h:571
static std::vector< uint8_t > decode(const std::string &encoded)
decode a base64 encoded string to binary.
Definition: base64.h:563
Generic Base64 codec.
Definition: base64.h:118
static std::string encode(const std::string_view &data, const alphabet_type &alphabet)
Definition: base64.h:254
static std::vector< uint8_t > decode(const std::string &encoded, const inverse_alphabet_type &inverse_alphabet)
Definition: base64.h:134
static std::string encode(const std::vector< uint8_t > &data, const alphabet_type &alphabet)
Definition: base64.h:240
std::array< int8_t, 256 > inverse_alphabet_type
type of all inverse mappings of alphabets.
Definition: base64.h:131
static std::string encode(const std::string &data, const alphabet_type &alphabet)
Definition: base64.h:247
static std::string encode(const char *data, const alphabet_type &alphabet)
Definition: base64.h:261
std::array< char, 64 > alphabet_type
type of all alphabet.
Definition: base64.h:123
static std::string encode_impl(const T &data, const alphabet_type &alphabet)
Definition: base64.h:269
#define HTTP_COMMON_EXPORT
Definition: http_common_export.h:15
constexpr inverse_alphabet_type inverse(const alphabet_type &v)
inverse
Definition: base64.h:431
constexpr int8_t find_pos_of_char(const alphabet_type &v, uint8_t character, size_t v_ndx=0)
find position of char in alphabet.
Definition: base64.h:367
std::index_sequence< 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, 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 > ndx_256
Definition: base64.h:413
constexpr inverse_alphabet_type make_inverse_array(const alphabet_type &v, std::index_sequence< I... >)
build inverse-alphabet.
Definition: base64.h:423
Definition: base64.h:345
Base64Impl::inverse_alphabet_type inverse_alphabet_type
type of all inverse mappings of alphabets.
Definition: base64.h:358
Base64Impl::alphabet_type alphabet_type
type of all alphabet.
Definition: base64.h:350
Definition: ut0tuple.h:57
bool distance(const dd::Spatial_reference_system *srs, const Geometry *g1, const Geometry *g2, double *distance, bool *is_null) noexcept
Computes the distance between two geometries.
Definition: distance.cc:40
Definition: base64.h:43
const char * begin(const char *const c)
Definition: base64.h:44
size_t size(const char *const c)
Definition: base64.h:46
const char * end(const char *const c)
Definition: base64.h:45
Base64Endianess
Definition: base64.h:41