|
template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar> |
static std::vector< uint8_t > | decode (const std::string &encoded, const inverse_alphabet_type &inverse_alphabet) |
|
template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar> |
static std::string | encode (const std::vector< uint8_t > &data, const alphabet_type &alphabet) |
|
template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar> |
static std::string | encode (const std::string &data, const alphabet_type &alphabet) |
|
template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar> |
static std::string | encode (const std::string_view &data, const alphabet_type &alphabet) |
|
template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar> |
static std::string | encode (const char *data, const alphabet_type &alphabet) |
|
Generic Base64 codec.
Base64 comes in many flavours:
- RFC4648 used by HTTP
- crypt
- bcrypt
- pbkdf2 in MCF
- UUencode
they differ by
- alphabet
- endianness
- padding
Base64Impl provides generic encode and decode methods which are parametrized by Endianness, Padding.
Parametrization with templates allows to provide:
- one implementation for all combinations
- without extra runtime overhead as dead code is removed by the compiler
Endianness
Little Endian
using Alphabet=Crypt
octet(hex): 55
uint32: ........ ........ 01010101 (LSB)
uint32: ...... ...... ....01 010101 (LSB)
sextet(hex): 1 15
Alphabet: / J
Out: J/
Big Endian
using Alphabet=Crypt
octet(hex): 55
uint32: 01010101 ........ ........ (LSB)
uint32: 010101 01.... ...... ...... (LSB)
sextet(hex): 15 10
Alphabet: J E
Out: JE
Padding
If padding is defined mandatory,
- at encode() each group of 4 sextets is filled by with the padding character.
- at decode() input must have padding.
If padding is not mandatory,
- at encode() no padding is added.
- at decode() padding is accepted, but not required.