CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
Base64.cpp File Reference
#include "Base64.h"
#include "UnitTestFramework.h"
#include "PsyTime.h"
#include <iostream>
Include dependency graph for Base64.cpp:

Go to the source code of this file.

Namespaces

namespace  cmlabs

Functions

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

Variables

static const std::string base64_chars

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.

◆ is_base64()

bool is_base64 ( unsigned char c)
inlinestatic

Definition at line 39 of file Base64.cpp.

Referenced by base64_decode().

Variable Documentation

◆ base64_chars

const std::string base64_chars
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/"

Definition at line 33 of file Base64.cpp.

Referenced by base64_decode(), and base64_encode().