Template Numerical Library: TNL::base64 Namespace Reference

Template Numerical Library version\ main:c7077e4fd

Loading...
Searching...
No Matches
Functions
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

Namespace for base64 encoding and decoding functions.

The actual algorithms are based on these sources:

- http://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.c
- https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c/
- https://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c

## 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

  data | Pointer to the encoded data (C string).
  data_size | Length 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

  input | Pointer to the encoded data (C string).
  input_length | Length of the input string.
  output | Pointer to a pre-allocated output buffer.
  output_length | Length 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

  data | Pointer to the data to be encoded.
  data_size | Length 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.