CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
Base64.h File Reference

Base64 encoding/decoding of arbitrary binary data (standard alphabet, '=' padding). More...

#include <string>
Include dependency graph for Base64.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  cmlabs

Functions

std::string base64_encode (std::string string_to_encode)
 Base64-encode a string's bytes.
std::string base64_encode (unsigned char const *, unsigned int len)
 Base64-encode a raw buffer.
std::string base64_decode (const char *encoded_string)
 Decode Base64 text.
std::string base64_decode (std::string const &s)
 Decode Base64 text.
bool cmlabs::Base64_UnitTest ()
 Base64 round-trip unit test.

Detailed Description

Base64 encoding/decoding of arbitrary binary data (standard alphabet, '=' padding).

Byte-order independent: Base64 operates on byte streams, so no endianness concerns arise. The functions live in the global namespace (third-party origin, adapted for CMSDK); the unit test is in cmlabs.

Definition in file Base64.h.

Function Documentation

◆ base64_decode() [1/2]

std::string base64_decode ( const char * encoded_string)

Decode Base64 text.

Parameters
encoded_stringNUL-terminated encoded text.
Returns
Decoded bytes.
Note
Non-alphabet characters terminate decoding.

Definition at line 49 of file Base64.cpp.

References base64_decode().

Referenced by base64_decode(), cmlabs::Base64_UnitTest(), and cmlabs::HTTPRequest::decodeBasicAuthorization().

◆ base64_decode() [2/2]

std::string base64_decode ( std::string const & s)

Decode Base64 text.

Parameters
sEncoded text.
Returns
Decoded bytes.

Definition at line 97 of file Base64.cpp.

References base64_chars, and is_base64().

◆ base64_encode() [1/2]

std::string base64_encode ( std::string string_to_encode)

Base64-encode a string's bytes.

Parameters
string_to_encodeRaw bytes (may contain NULs).
Returns
Encoded text.

Definition at line 44 of file Base64.cpp.

References base64_encode().

Referenced by cmlabs::RequestGateway::addAuthUser(), base64_encode(), cmlabs::Base64_UnitTest(), cmlabs::HTTPReply::createWebsocketHTTPReply(), cmlabs::HTTPRequest::createWebsocketRequest(), and cmlabs::HTTPRequest::setBasicAuthorization().

◆ base64_encode() [2/2]

std::string base64_encode ( unsigned char const * bytes_to_encode,
unsigned int len )

Base64-encode a raw buffer.

Parameters
bytes_to_encodeInput buffer.
lenNumber of bytes.
Returns
Encoded text.

Definition at line 54 of file Base64.cpp.

References base64_chars.