Nilorea Library
C utilities for networking, threading, graphics
n_base64.c File Reference

base64 encode decode function, adapted from https://opensource.apple.com/source/QuickTimeStreamingServer/QuickTimeStreamingServer-452/CommonUtilitiesLib/base64.c More...

#include "nilorea/n_base64.h"
#include <string.h>
+ Include dependency graph for n_base64.c:

Go to the source code of this file.

Functions

N_STRn_base64_decode (N_STR *bufcoded)
 decode a N_STR *string More...
 
size_t n_base64_decode_len (N_STR *string)
 get the length of 'input' if it was base64 decoded More...
 
N_STRn_base64_encode (N_STR *input)
 encode a N_STR *string More...
 
size_t n_base64_encode_len (N_STR *string)
 get the length of string if it was base64 encoded More...
 
FORCE_INLINE bool n_isalpha (char c)
 is_alpha More...
 
FORCE_INLINE bool n_islower (char c)
 test if char c is lowercase More...
 
FORCE_INLINE bool n_isupper (char c)
 test if char c is uppercase More...
 
FORCE_INLINE char n_tolower (char c)
 is_alpha More...
 
FORCE_INLINE char n_toupper (char c)
 is_alpha More...
 

Variables

static const bool ascii_lower_case_lookup_table [256]
 static lower case lookup ascii table More...
 
static const bool ascii_upper_case_lookup_table [256]
 static upper case lookup ascii table More...
 
static const char basis_64 []
 static lookup base64 alphabet More...
 
static const unsigned char pr2six [256]
 static lookup ascii table More...
 

Detailed Description

base64 encode decode function, adapted from https://opensource.apple.com/source/QuickTimeStreamingServer/QuickTimeStreamingServer-452/CommonUtilitiesLib/base64.c

Author
Castagnier Mickael
Version
1.0
Date
10/11/2022

Definition in file n_base64.c.

Function Documentation

◆ n_base64_decode_len()

size_t n_base64_decode_len ( N_STR input)

get the length of 'input' if it was base64 decoded

Parameters
inputthe N_STR *string for which we need the decoded size
Returns
length of the decoded string or 0 on error / invalid input

Definition at line 152 of file n_base64.c.

References __n_assert, and pr2six.

◆ n_base64_encode_len()

int n_base64_encode_len ( N_STR string)

get the length of string if it was base64 encoded

Parameters
stringthe N_STR *string for which we need the encoded size
Returns
length of the encoded string or 0 on error

Definition at line 235 of file n_base64.c.

References __n_assert.

Referenced by n_base64_encode().

+ Here is the caller graph for this function:

Variable Documentation

◆ ascii_lower_case_lookup_table

const bool ascii_lower_case_lookup_table[256]
static
Initial value:
=
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

static lower case lookup ascii table

Definition at line 61 of file n_base64.c.

Referenced by n_isalpha(), n_islower(), and n_toupper().

◆ ascii_upper_case_lookup_table

const bool ascii_upper_case_lookup_table[256]
static
Initial value:
=
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

static upper case lookup ascii table

Definition at line 37 of file n_base64.c.

Referenced by n_isalpha(), n_isupper(), and n_tolower().

◆ basis_64

const char basis_64[]
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

static lookup base64 alphabet

Definition at line 225 of file n_base64.c.

Referenced by n_base64_encode().

◆ pr2six

const unsigned char pr2six[256]
static
Initial value:
=
{
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
}

static lookup ascii table

Definition at line 13 of file n_base64.c.

Referenced by n_base64_decode(), and n_base64_decode_len().