Template Numerical Library version\ main:bb09b17
Loading...
Searching...
No Matches
TNL::base64 Namespace Reference

Namespace for base64 encoding and decoding functions. More...

Functions

std::pair< std::size_t, std::unique_ptr< std::uint8_t[] > > decode (const char *data, const std::size_t data_size)
 Do a base64 decoding of the given data.
 
std::ptrdiff_t decode_block (const char *input, std::size_t input_length, std::uint8_t *output, std::size_t output_length)
 Internal base64 decoding function.
 
std::unique_ptr< char[] > encode (const std::uint8_t *data, std::size_t data_size)
 Do a base64 encoding of the given data.
 
std::size_t get_encoded_length (std::size_t byte_length)
 Get the length of base64-encoded block for given data byte length.
 
template<typename HeaderType = std::uint64_t, typename T >
void write_encoded_block (const T *data, const std::size_t data_length, std::ostream &output_stream)
 Write a base64-encoded block of data into the given stream.
 

Detailed Description

Function Documentation

◆ decode()

std::pair< std::size_t, std::unique_ptr< std::uint8_t[] > > TNL::base64::decode ( const char * data,
const std::size_t data_size )
inline

Do a base64 decoding of the given data.

Parameters
dataPointer to the encoded data (C string).
data_sizeLength of the input string.
Returns
A pair of the decoded data length and a std::unique_ptr to the decoded data.

◆ decode_block()

std::ptrdiff_t TNL::base64::decode_block ( const char * input,
std::size_t input_length,
std::uint8_t * output,
std::size_t output_length )
inline

Internal base64 decoding function.

Parameters
inputPointer to the encoded data (C string).
input_lengthLength of the input string.
outputPointer to a pre-allocated output buffer.
output_lengthLength of the output buffer.
Returns
Size of the decoded data (in bytes).

◆ encode()

std::unique_ptr< char[] > TNL::base64::encode ( const std::uint8_t * data,
std::size_t data_size )
inline

Do a base64 encoding of the given data.

Parameters
dataPointer to the data to be encoded.
data_sizeLength of the input data (in bytes).
Returns
A std::unique_ptr to the encoded data.

◆ write_encoded_block()

template<typename HeaderType = std::uint64_t, typename T >
void TNL::base64::write_encoded_block ( const T * data,
const std::size_t data_length,
std::ostream & output_stream )

Write a base64-encoded block of data into the given stream.

The encoded data is prepended with a short header, which is the base64-encoded byte length of the data. The type of the byte length value is HeaderType.