Base 64
[Libraries]

The Make Controller Base 64 library provides a way to decode and encode base 64 data. More...


Functions

int Base64_Encode (char *dest, int dest_size, const char *src, int src_size)
 Base 64 encode a block of data.
bool Base64_Decode (char *dest, int *dest_size, const char *src, int src_size)
 Decode a Base64 string into a block of data.

Detailed Description

The Make Controller Base 64 library provides a way to decode and encode base 64 data.

This is often handy when you need to send raw/binary data (as opposed to text) through a text based format, like XML or JSON.

Most code lifted from gnulib - http://savannah.gnu.org/projects/gnulib - and written by Simon Josefsson.


Function Documentation

bool Base64_Decode ( char *  dest,
int *  dest_size,
const char *  src,
int  src_size 
)

Decode a Base64 string into a block of data.

Parameters:
dest A pointer to the block of data to write in.
dest_size A pointer to the maximum number of bytes to write into dest. The number of bytes successfully written will be stored in this value upon return.
src The base 64 string to decode.
src_size The size of the base 64 string.
Returns:
True on successful decode, false on failure.
Example
  #define BUFF_SIZE 256
  char decode_buf[BUFF_SIZE];
  int decode_size = BUFF_SIZE;
  bool result = Base64_Decode(decode_buf, &decode_size, "dGVzdA==", 8);
  // we now have "test" in decode_buf, and decode_size is set to 6

Definition at line 274 of file base64.c.

int Base64_Encode ( char *  dest,
int  dest_size,
const char *  src,
int  src_size 
)

Base 64 encode a block of data.

Provide a buffer to write into and to read from. As Base64 encoding results in 4 bytes for every 3 source bytes, ensure your destination buffer is large enough.

Parameters:
dest The buffer that the encoded string will be written into.
dest_size The maximum number of bytes to write into the destination buffer.
src A block of data to encode.
src_size The number of bytes from src to encode.
Returns:
The length of the generated string (not including null termination).
Example
  #define BUFF_SIZE 256
  char encode_buf[BUFF_SIZE];
  int len = Base64_Encode(encode_buf, BUFF_SIZE, "test", 4);
  // we now have "dGVzdA==" in encode_buf, and len is 8

Definition at line 66 of file base64.c.