Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Base64.cxx File Reference
#include "utils/Base64.hxx"
#include <stdint.h>
#include "utils/macros.h"

Go to the source code of this file.

Functions

std::string base64_encode (const std::string &binary)
 Performs encoding of data in base64 format.
 
unsigned nib64_to_byte (char c)
 Decode a single base64 nibble.
 
bool base64_decode (const std::string &base64, std::string *data)
 Performs decoding of data from base64 format to binary.
 

Variables

static const char nib64 []
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Helper function to perform encoding & decoding of Base64 data.

Author
Balazs Racz
Date
31 July 2019

Definition in file Base64.cxx.

Function Documentation

◆ base64_decode()

bool base64_decode ( const std::string &  base64,
std::string *  data 
)

Performs decoding of data from base64 format to binary.

Parameters
base64base64 encoded data
datadecoded data will be written here.
Returns
true if decoding was successful. false if the encoding was erroneous, in which case the content of data is undefined.

Definition at line 113 of file Base64.cxx.

◆ base64_encode()

std::string base64_encode ( const std::string &  binary)

Performs encoding of data in base64 format.

Parameters
binarydata to encode
Returns
base64 representation. The size will be (binary.size() + 2) / 3 * 4.

Definition at line 43 of file Base64.cxx.

◆ nib64_to_byte()

unsigned nib64_to_byte ( char  c)

Decode a single base64 nibble.

Parameters
cis the base64 nibble.
Returns
64 if this is the padding nibble; 65 if it's an invalid nibble, or 0..63 if it's a valid nibble.

Definition at line 83 of file Base64.cxx.

Variable Documentation

◆ nib64

const char nib64[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 40 of file Base64.cxx.