ldas-tools-al 2.6.4
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
Base64 Class Reference

Base 64 Conversion. More...

#include <base64.hh>

Public Types

typedef LDASTools::AL::bit_vector bit_vector
 
typedef LDASTools::AL::bit_vector bit_vector
 

Static Public Member Functions

static size_t encode (std::string &Destination, const bit_vector &Source)
 Encode bit_vector.
 
static size_t encode (char *destination, const void *source, size_t size)
 Encode generic 8 bit data.
 
static size_t decode (bit_vector &Destination, const std::string &Source)
 Decode bit_vector.
 
static size_t decode (void *destination, const char *source)
 Decode generic 8 bit data.
 
static size_t calculateEncodedSize (size_t bytes)
 Compute number of output bytes given the number of input bytes.
 
static size_t calculateDecodedSize (const char *s)
 Compute number of output bytes given a null terminated string.
 
static void setNumCharactersPerLine (const int num)
 Establish the number of characters per line.
 
static size_t encode (std::string &Destination, const bit_vector &Source)
 Encode bit_vector.
 
static size_t encode (char *destination, const void *source, size_t size)
 Encode generic 8 bit data.
 
static size_t decode (bit_vector &Destination, const std::string &Source)
 Decode bit_vector.
 
static size_t decode (void *destination, const char *source)
 Decode generic 8 bit data.
 
static size_t calculateEncodedSize (size_t bytes)
 Compute number of output bytes given the number of input bytes.
 
static size_t calculateDecodedSize (const char *s)
 Compute number of output bytes given a null terminated string.
 
static void setNumCharactersPerLine (const int num)
 Establish the number of characters per line.
 

Static Private Member Functions

static bool getChar (const char **source, unsigned char &c)
 Get next Base64 value.
 
static bool getChar (const char **source, unsigned char &c)
 Get next Base64 value.
 

Static Private Attributes

static const char * mTable
 Base 64 translation table.
 
static int mCharsPerLine
 Number of characters per line.
 

Detailed Description

Base 64 Conversion.

This class is used to convert to and from Base 64. Base 64 is a way to encode binary data using printable ASCII characters. It uses 4 characters for every 3 bytes.

This is a static class.

Member Typedef Documentation

◆ bit_vector [1/2]

◆ bit_vector [2/2]

Member Function Documentation

◆ calculateDecodedSize() [1/2]

size_t Base64::calculateDecodedSize ( const char *  s)
static

Compute number of output bytes given a null terminated string.

Calculate Decoded Size.

Calculates the number of bytes which the passed Base-64 string will decode into.

Parameters
sThe string to check.
Returns
size_t The number of bytes.

◆ calculateDecodedSize() [2/2]

static size_t Base64::calculateDecodedSize ( const char *  s)
static

Compute number of output bytes given a null terminated string.

◆ calculateEncodedSize() [1/2]

size_t Base64::calculateEncodedSize ( size_t  size)
static

Compute number of output bytes given the number of input bytes.

Calculate Encoded Size.

Calculates the number of characters required to represent the requested number of bytes in Base-64. This does not include the null-terminator.

Parameters
sizeThe number of bytes to encode.
Returns
size_t The size of the encoded string (minus the null-terminator).

◆ calculateEncodedSize() [2/2]

static size_t Base64::calculateEncodedSize ( size_t  bytes)
static

Compute number of output bytes given the number of input bytes.

◆ decode() [1/4]

size_t Base64::decode ( bit_vector Destination,
const std::string &  Source 
)
static

Decode bit_vector.

Decode base64 data back into a bit_vector

Parameters
DestinationStorage space for decoded data
SourceStorage space for the encoded data
Returns
size_t Number of bytes in the Destination buffer.

◆ decode() [2/4]

static size_t Base64::decode ( bit_vector Destination,
const std::string &  Source 
)
static

Decode bit_vector.

◆ decode() [3/4]

size_t Base64::decode ( void *  destination,
const char *  source 
)
static

Decode generic 8 bit data.

This translates a Base-64 encoded string into binary data.

Parameters
destinationThe location to write the decoded data. This must be large enough to store the data. The required size can be calculated via the 'calculateDecodedSize' method.
sourceBase64 data. Decoding will stop when the first non-Base64 character, an '=', or a null terminator occurs.
Returns
The number of bytes decoded.

◆ decode() [4/4]

static size_t Base64::decode ( void *  destination,
const char *  source 
)
static

Decode generic 8 bit data.

◆ encode() [1/4]

size_t Base64::encode ( char *  destination,
const void *  source,
size_t  size 
)
static

Encode generic 8 bit data.

Encodes Base64.

This method translates a block of binary data into Base-64 encoded data. The encoded data is stored in the memory location provided by the user. This destination buffer must be large enough to store the result. The user may calculate what the size needs to be via the calculateEncodedSize method (be sure to add 1 for the null character). This method appends a null character to the end of the encoded string.

Parameters
destinationThe buffer in which to store the encoded data.
sourceThe buffer to encode.
sizeThe number of bytes in the buffer.
Returns
The length of the destination string (not including the terminating null).

◆ encode() [2/4]

static size_t Base64::encode ( char *  destination,
const void *  source,
size_t  size 
)
static

Encode generic 8 bit data.

◆ encode() [3/4]

size_t Base64::encode ( std::string &  Destination,
const bit_vector Source 
)
static

Encode bit_vector.

Parameters
[out]DestinationThe buffer to hold the base 64 encoded result.
[in]SourceThe buffer holding the 8-bit data to encode.
Returns
The number of bytes written to Destination.

◆ encode() [4/4]

static size_t Base64::encode ( std::string &  Destination,
const bit_vector Source 
)
static

Encode bit_vector.

◆ getChar() [1/2]

bool Base64::getChar ( const char **  source,
unsigned char &  c 
)
staticprivate

Get next Base64 value.

Parameters
sourceThe address of the pointer to the next Base-64 character in the string. The pointer will be updated by this method as it searches along the string.
cThe value of the next Base64 character found (0-63). If a character was not found, the value is
Returns
True if a Base-64 character other than '=' was found. false indicates that the string is finished.

◆ getChar() [2/2]

static bool Base64::getChar ( const char **  source,
unsigned char &  c 
)
staticprivate

Get next Base64 value.

◆ setNumCharactersPerLine() [1/2]

void Base64::setNumCharactersPerLine ( const int  num)
static

Establish the number of characters per line.

Set number of characters per line.

Sets number of characters per line for the encoded data.

Parameters
numNumber of characters.
Returns
size_t The number of bytes.

◆ setNumCharactersPerLine() [2/2]

static void Base64::setNumCharactersPerLine ( const int  num)
static

Establish the number of characters per line.

Member Data Documentation

◆ mCharsPerLine

static int Base64::mCharsPerLine
staticprivate

Number of characters per line.

Default is 76 (based on MIME).

◆ mTable

static const char * Base64::mTable
staticprivate

Base 64 translation table.

An array containing the Base64 characters in order.


The documentation for this class was generated from the following files: