base64

Public Functions

Public Static Functions


Output_iterator encode (Input_iterator in_begin, Input_iterator in_end, Output_iterator out, alphabet alphabet=alphabet::normal)

Encodes all the elements from in_begin to in_end to out.

Warning

The source and destination cannot overlap. The destination must be able to hold at least required_encode_size(std::distance(in_begin, in_end)), otherwise the behavior depends on the output iterator.

Template Parameters

  • Input_iterator - the source; the returned elements are cast to std::uint8_t and should not be greater than 8 bits
  • Output_iterator - the destination; the elements written to it are from the type char

Parameters

  • in_begin - the beginning of the source
  • in_end - the ending of the source
  • out - the destination iterator
  • alphabet - which alphabet should be used

Returns

    the iterator to the next element past the last element copied

Exceptions

  • see - Input_iterator and Output_iterator


std::string encode (const std::string &str, alphabet alphabet=alphabet::standard)

Encodes a string.

Parameters

  • str - the string that should be encoded
  • alphabet - which alphabet should be used

Returns

    the encoded base64 string

Exceptions


std::string encode (const char buffer, std::size_t size, alphabet alphabet=alphabet::standard)*

Encodes a char array.

Parameters

  • buffer - the char array
  • size - the size of the array
  • alphabet - which alphabet should be used

Returns

    the encoded string


Output_iterator decode (Input_iterator in_begin, Input_iterator in_end, Output_iterator out, alphabet alphabet=alphabet::auto_, decoding_behavior behavior=decoding_behavior::moderate)

Decodes all the elements from in_begin to in_end to out. in_begin may point to the same location as out, in other words: inplace decoding is possible.

Warning

The destination must be able to hold at least required_decode_size(std::distance(in_begin, in_end)), otherwise the behavior depends on the output iterator.

Template Parameters

  • Input_iterator - the source; the returned elements are cast to char
  • Output_iterator - the destination; the elements written to it are from the type std::uint8_t

Parameters

  • in_begin - the beginning of the source
  • in_end - the ending of the source
  • out - the destination iterator
  • alphabet - which alphabet should be used
  • behavior - the behavior when an error was detected

Returns

    the iterator to the next element past the last element copied

Exceptions

  • base64_error - depending on the set behavior
  • see - Input_iterator and Output_iterator


std::string decode (const std::string &str, alphabet alphabet=alphabet::auto_, decoding_behavior behavior=decoding_behavior::moderate)

Decodes a string.

Parameters

  • str - the base64 encoded string
  • alphabet - which alphabet should be used
  • behavior - the behavior when an error was detected

Returns

    the decoded string

Exceptions


std::string decode (const char buffer, std::size_t size, alphabet alphabet=alphabet::auto_, decoding_behavior behavior=decoding_behavior::moderate)*

Decodes a string.

Parameters

  • buffer - the base64 encoded buffer
  • size - the size of the buffer
  • alphabet - which alphabet should be used
  • behavior - the behavior when an error was detected

Returns

    the decoded string

Exceptions


void decode_inplace (std::string &str, alphabet alphabet=alphabet::auto_, decoding_behavior behavior=decoding_behavior::moderate)

Decodes a string inplace.

Parameters

  • str - the base64 encoded string
  • alphabet - which alphabet should be used
  • behavior - the behavior when an error was detected

Exceptions


char * decode_inplace (char str, std::size_t size, alphabet alphabet=alphabet::auto_, decoding_behavior behavior=decoding_behavior::moderate)*

Decodes a char array inplace.

Parameters

  • str - the string array
  • size - the length of the array
  • alphabet - which alphabet should be used
  • behavior - the behavior when an error was detected

Returns

    the pointer to the next element past the last element decoded

Exceptions


std::size_t max_decode_size (std::size_t size) noexcept

Returns the required decoding size for a given size. The value is calculated with the following formula: $$ \lceil \frac{size}{4} \rceil \cdot 3 $$

Parameters

  • size - the size of the encoded input

Returns

    the size of the resulting decoded buffer; this the absolute maximum


std::size_t required_encode_size (std::size_t size) noexcept

Returns the required encoding size for a given size. The value is calculated with the following formula: $$ \lceil \frac{size}{3} \rceil \cdot 4 $$

Parameters

  • size - the size of the decoded input

Returns

    the size of the resulting encoded buffer