TSDuck v3.43-4441
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

Base64 encoder and decoder. More...

#include <tsBase64.h>

Public Member Functions

 Base64 (size_t line_size=DEFAULT_LINE_SIZE)
 Constructor.
 
bool decodeAdd (ByteBlock &bin, const UString &b64)
 Decode Base64 string and return partial binary data.
 
bool decodeTerminate (ByteBlock &bin)
 Terminate Base64 decoding.
 
void encodeAdd (UString &b64, const void *data, size_t size)
 Encode binary data and return partial Base64 string.
 
void encodeTerminate (UString &b64)
 Terminate binary data encoding, generate potential end of Base64 stream.
 
void reset ()
 Reset the encoder and decoder.
 

Static Public Member Functions

static bool Decode (ByteBlock &bin, const UString &b64)
 Bulk Base64 decoding.
 
static ByteBlock Decoded (const UString &b64)
 Bulk Base64 decoding.
 
static void Encode (UString &b64, const void *data, size_t size, size_t line_size=DEFAULT_LINE_SIZE)
 Bulk Base64 encoding.
 
static UString Encoded (const void *data, size_t size, size_t line_size=DEFAULT_LINE_SIZE)
 Bulk Base64 encoding.
 

Static Public Attributes

static constexpr size_t BIN_BLOCK_SIZE = 3
 Base64 input bytes block size.
 
static constexpr size_t DEFAULT_LINE_SIZE = 76
 Default output line size.
 
static constexpr UChar PAD_CHAR = u'='
 Base64 padding character at end of stream.
 
static constexpr size_t STR_BLOCK_SIZE = 4
 Base64 output characters block size.
 

Detailed Description

Base64 encoder and decoder.

Constructor & Destructor Documentation

◆ Base64()

ts::Base64::Base64 ( size_t  line_size = DEFAULT_LINE_SIZE)
explicit

Constructor.

Parameters
[in]line_sizeOutput text line size, when producing encoded Base64. When zero, do not generate new-line characters.

Member Function Documentation

◆ encodeAdd()

void ts::Base64::encodeAdd ( UString b64,
const void *  data,
size_t  size 
)

Encode binary data and return partial Base64 string.

Some input data may be internally kept, waiting for more data to encode. Call encodeTerminate() to properly terminate the encoding of data.

Parameters
[in,out]b64Output string. Produced characters are appended at the end of output.
[in]dataAddress of data to encode.
[in]sizeSize in bytes of data to encode.

◆ encodeTerminate()

void ts::Base64::encodeTerminate ( UString b64)

Terminate binary data encoding, generate potential end of Base64 stream.

Parameters
[in,out]b64Output string. Produced characters are appended at the end of output.

◆ decodeAdd()

bool ts::Base64::decodeAdd ( ByteBlock bin,
const UString b64 
)

Decode Base64 string and return partial binary data.

Some input Base64 characters may be internally kept, waiting for more characters to decode. Call decodeTerminate() to properly terminate and validate the decoding.

Parameters
[in,out]binOutput binary data. Produced bytes are appended at the end of bin.
[in]b64Partial base64 string.
Returns
True on success, false on invalid input Base64 format.

◆ decodeTerminate()

bool ts::Base64::decodeTerminate ( ByteBlock bin)

Terminate Base64 decoding.

Parameters
[in,out]binOutput binary data. Produced bytes are appended at the end of bin.
Returns
True on success, false on invalid input Base64 format.

◆ Encode()

static void ts::Base64::Encode ( UString b64,
const void *  data,
size_t  size,
size_t  line_size = DEFAULT_LINE_SIZE 
)
static

Bulk Base64 encoding.

Parameters
[out]b64Output Base64 string.
[in]dataAddress of data to encode.
[in]sizeSize in bytes of data to encode.
[in]line_sizeOutput text line size, when producing encoded Base64. When zero, do not generate new-line characters.

◆ Encoded()

static UString ts::Base64::Encoded ( const void *  data,
size_t  size,
size_t  line_size = DEFAULT_LINE_SIZE 
)
static

Bulk Base64 encoding.

Parameters
[in]dataAddress of data to encode.
[in]sizeSize in bytes of data to encode.
[in]line_sizeOutput text line size, when producing encoded Base64. When zero, do not generate new-line characters.
Returns
Output Base64 string.

◆ Decode()

static bool ts::Base64::Decode ( ByteBlock bin,
const UString b64 
)
static

Bulk Base64 decoding.

Parameters
[out]binOutput binary data.
[in]b64Full Base64 string.
Returns
True on success, false on invalid input Base64 format.

◆ Decoded()

static ByteBlock ts::Base64::Decoded ( const UString b64)
static

Bulk Base64 decoding.

Parameters
[in]b64Full Base64 string.
Returns
Output binary data. In case of error, return the successfully decoded part. It is not possible to determine if the input Base64 string was full correct or only partially decoded.

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