# 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_buff_size | calcEncodedStringSize | Calculate size of encoding result of a string of the given size. |
v_buff_size | 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:
|
oatpp::String | decode | Multiple implementations:
|
# 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_buff_size calcEncodedStringSize(v_buff_size 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_buff_size calcDecodedStringSize(const char* data, v_buff_size size, v_buff_size& 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_buff_size size, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)
# Base64::encode
- 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_buff_size size, const char* alphabet = ALPHABET_BASE64)
- 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
- 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_buff_size size, const char* auxiliaryChars = ALPHABET_BASE64_AUXILIARY_CHARS)
- 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 - data to decode.
- @param auxiliaryChars - configurable auxiliary chars.
- @return - decoded data as oatpp::String.
- @throws - Base64::DecodingError
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)