MySQL 8.0.39
Source Code Documentation
Base64Impl Class Reference

Generic Base64 codec. More...

#include <base64.h>

Public Types

using alphabet_type = std::array< char, 64 >
 type of all alphabet. More...
 
using inverse_alphabet_type = std::array< int8_t, 256 >
 type of all inverse mappings of alphabets. More...
 

Static Public Member Functions

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)
 

Detailed Description

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.

Member Typedef Documentation

◆ alphabet_type

using Base64Impl::alphabet_type = std::array<char, 64>

type of all alphabet.

◆ inverse_alphabet_type

using Base64Impl::inverse_alphabet_type = std::array<int8_t, 256>

type of all inverse mappings of alphabets.

  • -1 invalid
  • 0-63 position into alphabet

Member Function Documentation

◆ decode()

template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
static std::vector< uint8_t > Base64Impl::decode ( const std::string &  encoded,
const inverse_alphabet_type inverse_alphabet 
)
inlinestatic

◆ encode()

template<Base64Endianess endianess, bool PaddingMandatory, char PaddingChar>
static std::string Base64Impl::encode ( const std::vector< uint8_t > &  data,
const alphabet_type alphabet 
)
inlinestatic

The documentation for this class was generated from the following file: