Base64.hpp

This File On Github
Ask A Question

API: latest
module: oatpp
#include "oatpp/encoding/Base64.hpp"

Base64

Base64 - encoder/decoder.

namespace oatpp { namespace encoding { 
  class Base64 {}
}}

Fields

Type Name Summary
const char* const ALPHABET_BASE64 Standard base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '+', '/', '=']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.
const char* const ALPHABET_BASE64_URL URL base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '-', '_', '=']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.
const char* const ALPHABET_BASE64_URL_SAFE URL safe base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '.', '_', '-']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.
const char* const ALPHABET_BASE64_AUXILIARY_CHARS Standard base64 Alphabet auxiliary chars ['+', '/', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.
const char* const ALPHABET_BASE64_URL_AUXILIARY_CHARS URL base64 Alphabet auxiliary chars ['-', '_', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.
const char* const ALPHABET_BASE64_URL_SAFE_AUXILIARY_CHARS URL safe base64 Alphabet auxiliary chars ['.', '_', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.

Methods

Return Type Name Summary
v_int32 calcEncodedStringSize Calculate size of encoding result of a string of the given size.
v_int32 calcDecodedStringSize Calculate size of decoding result. this method assumes that data passed as a param consists of standard base64 set of chars
bool isBase64String Check if data is a valid base64 encoded string.
oatpp::String encode Multiple implementations:
  1. Encode data as base64 string.
  2. Encode data as base64 string.
oatpp::String decode Multiple implementations:
  1. Decode base64 encoded data. This method assumes that data passed as a param consists of standard base64 set of chars
  2. Decode base64 encoded data. This method assumes that data passed as a param consists of standard base64 set of chars

Base64::ALPHABET_BASE64

Standard base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '+', '/', '=']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.

static const char* const ALPHABET_BASE64

Base64::ALPHABET_BASE64_URL

URL base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '-', '_', '=']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.

static const char* const ALPHABET_BASE64_URL

Base64::ALPHABET_BASE64_URL_SAFE

URL safe base64 Alphabet - ['A'-'Z', 'a'-'z', '0'-'9', '.', '_', '-']. Alphabet is array of 65 chars. 64 chars encoding chars, and 65th padding char.

static const char* const ALPHABET_BASE64_URL_SAFE

Base64::ALPHABET_BASE64_AUXILIARY_CHARS

Standard base64 Alphabet auxiliary chars ['+', '/', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.

static const char* const ALPHABET_BASE64_AUXILIARY_CHARS

Base64::ALPHABET_BASE64_URL_AUXILIARY_CHARS

URL base64 Alphabet auxiliary chars ['-', '_', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.

static const char* const ALPHABET_BASE64_URL_AUXILIARY_CHARS

Base64::ALPHABET_BASE64_URL_SAFE_AUXILIARY_CHARS

URL safe base64 Alphabet auxiliary chars ['.', '_', '=']. alphabet auxiliary chars - last 3 chars of alphabet including padding char.

static const char* const ALPHABET_BASE64_URL_SAFE_AUXILIARY_CHARS

Base64::calcEncodedStringSize

Calculate size of encoding result of a string of the given size.

  • @param size - size of string to encode.
  • @return - size of encoding result of a string of the given size

static v_int32 calcEncodedStringSize(v_int32 size)

Base64::calcDecodedStringSize

Calculate size of decoding result. this method assumes that data passed as a param consists of standard base64 set of chars ['A'-'Z', 'a'-'z', '0'-'9'] and three configurable auxiliary chars.

  • @param data - pointer to data.
  • @param size - size of the data.
  • @param base64StrLength - out parameter. Size of base64 valid encoded string. It may appear to be less then size.
  • @param auxiliaryChars - configurable auxiliary chars.
  • @return - size of decoded data. If data passed is not a base64 string then -1 is returned.

static v_int32 calcDecodedStringSize(const char* data, v_int32 size, v_int32& base64StrLength, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)

Base64::isBase64String

Check if data is a valid base64 encoded string.

  • @param data - pointer to data.
  • @param size - data size.
  • @param auxiliaryChars - configurable auxiliary chars.
  • @return (calcDecodedStringSize(data, size, base64StrLength, auxiliaryChars) >= 0).

static bool isBase64String(const char* data, v_int32 size, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)

Base64::encode

  1. Encode data as base64 string.
    • @param data - pointer to data.
    • @param size - data size.
    • @param alphabet - base64 alphabet to use.
    • @return - encoded base64 string as oatpp::String.
    static oatpp::String encode(const void* data, v_int32 size, const char* alphabet = ALPHABET_BASE64)
    
  2. Encode data as base64 string.
    • @param data - data to encode.
    • @param alphabet - base64 alphabet to use.
    • @return - encoded base64 string as oatpp::String.
    static oatpp::String encode(const oatpp::String& data, const char* alphabet = ALPHABET_BASE64)
    

Base64::decode

  1. Decode base64 encoded data. This method assumes that data passed as a param consists of standard base64 set of chars ['A'-'Z', 'a'-'z', '0'-'9'] and three configurable auxiliary chars.
    • @param data - pointer to data to decode.
    • @param size - encoded data size.
    • @param auxiliaryChars - configurable auxiliary chars.
    • @return - decoded data as oatpp::String.
    • @throws - Base64::DecodingError
    static oatpp::String decode(const char* data, v_int32 size, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)
    
  2. Decode base64 encoded data. This method assumes that data passed as a param consists of standard base64 set of chars ['A'-'Z', 'a'-'z', '0'-'9'] and three configurable auxiliary chars.
    static oatpp::String decode(const oatpp::String& data, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)
    

Base64::DecodingError

DecodingError.

namespace oatpp { namespace encoding { 
  class Base64 {
    class DecodingError : public std::runtime_error {}
  };
}}

Methods

Return Type Name Summary
[none] DecodingError Constructor.

Base64::DecodingError::DecodingError

Constructor.

  • @param message - error message.

DecodingError(const char* message)
  :std::runtime_error(message)