LMMS
Loading...
Searching...
No Matches
base64.c File Reference
#include "base64.h"
#include "serd_internal.h"
#include "string_utils.h"
#include "serd/serd.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

static void encode_chunk (uint8_t out[4], const uint8_t in[3], size_t n_in)
size_t serd_base64_get_length (const size_t size, const bool wrap_lines)
bool serd_base64_encode (uint8_t *const str, const void *const buf, const size_t size, const bool wrap_lines)
static uint8_t unmap (const uint8_t in)
static size_t decode_chunk (const uint8_t in[4], uint8_t out[3])
voidserd_base64_decode (const uint8_t *str, size_t len, size_t *size)

Variables

static const uint8_t b64_map []
static const char b64_unmap []

Function Documentation

◆ decode_chunk()

size_t decode_chunk ( const uint8_t in[4],
uint8_t out[3] )
inlinestatic

Decode 4 base64 characters to 3 raw bytes.

◆ encode_chunk()

void encode_chunk ( uint8_t out[4],
const uint8_t in[3],
size_t n_in )
inlinestatic

Encode 3 raw bytes to 4 base64 characters.

◆ serd_base64_encode()

bool serd_base64_encode ( uint8_t * str,
const void * buf,
size_t size,
bool wrap_lines )

Encode size bytes of buf into str, which must be large enough.

Parameters
strOutput string buffer.
bufInput binary data.
sizeNumber of bytes to encode from buf.
wrap_linesWrap lines at 76 characters to conform to RFC 2045.
Returns
True iff str contains newlines.

◆ serd_base64_get_length()

size_t serd_base64_get_length ( size_t size,
bool wrap_lines )

Return the number of bytes required to encode size bytes in base64.

Parameters
sizeThe number of input (binary) bytes to encode.
wrap_linesWrap lines at 76 characters to conform to RFC 2045.
Returns
The length of the base64 encoding, excluding null terminator.

◆ unmap()

uint8_t unmap ( const uint8_t in)
inlinestatic

Variable Documentation

◆ b64_map

const uint8_t b64_map[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Base64 encoding table.

See also
RFC3548 S3.

◆ b64_unmap

const char b64_unmap[]
static
Initial value:
=
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$m$$$ncdefghijkl$$$$$$"
"$/0123456789:;<=>?@ABCDEFGH$$$$$$IJKLMNOPQRSTUVWXYZ[\\]^_`ab$$$$"
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"

Base64 decoding table.

This is indexed by encoded characters and returns the numeric value used for decoding, shifted up by 47 to be in the range of printable ASCII. A '$' is a placeholder for characters not in the base64 alphabet.