Pico Libraries
Functions
pico_b64.h File Reference

A simple Base64 encoding/decoding library. More...

#include <stddef.h>
Include dependency graph for pico_b64.h:

Go to the source code of this file.

Functions

size_t b64_encoded_size (size_t len)
 Returns the Base64 encoded size of an array of bytes (NOTE: This does not include a null terminator) More...
 
size_t b64_decoded_size (const char *src, size_t len)
 Returns the decoded size of a Base64 string (NOTE: This does not include a null terminator) More...
 
size_t b64_encode (char *dst, const unsigned char *src, size_t len)
 Encodes an array of bytes into a Base64 encoded string (NOTE: A null terminator is not appended) More...
 
size_t b64_decode (unsigned char *dst, const char *src, size_t len)
 Decodes a Base64 encoded string into an array of bytes (NOTE: A null terminator is not appended) More...
 

Detailed Description

A simple Base64 encoding/decoding library.


Licensing information at end of header

Features:

Summary:

This header is a repackaged and modified version of the b64.c library by Joseph Werle. The most significant change is that there is no dynamic memory allocation. Instead, there are functions that compute the size of encoded/decoded buffers in advance. Other changes are mostly cosmetic and are intended to make the code easier to understand.

Base64 is a means of encoding binary data as plain ASCII. Each Base64 character represents log2(64) = 6 bits, meaning the encoded bytes occupy more memory that the original. This encoding is useful in circumstances where data needs to be stored or transmitted, but where a binary format is not possible nor desired. Applications include embedding binary data in JSON/XML, as well as representing cryptographic certificates and signatures in plain text.

Usage:

To use this library in your project, add the following

#define PICO_B64_IMPLEMENTATION #include "pico_b64.h"

to a source file (once), then simply include the header normally.

Function Documentation

◆ b64_encoded_size()

size_t b64_encoded_size ( size_t  len)

Returns the Base64 encoded size of an array of bytes (NOTE: This does not include a null terminator)

Parameters
lenThe length of the array of bytes

◆ b64_decoded_size()

size_t b64_decoded_size ( const char *  src,
size_t  len 
)

Returns the decoded size of a Base64 string (NOTE: This does not include a null terminator)

Parameters
srcThe string to decode. This is only used to determine padding and is not traversed
lenThe length of the encoded (src) string

◆ b64_encode()

size_t b64_encode ( char *  dst,
const unsigned char *  src,
size_t  len 
)

Encodes an array of bytes into a Base64 encoded string (NOTE: A null terminator is not appended)

Parameters
dstEncoded character (destination) buffer
srcByte array to be encoded
lenLength of src in bytes
Returns
Number of encoded characters

◆ b64_decode()

size_t b64_decode ( unsigned char *  dst,
const char *  src,
size_t  len 
)

Decodes a Base64 encoded string into an array of bytes (NOTE: A null terminator is not appended)

Parameters
dstDecoded byte array (destination)
srcCharacter array to be decoded
lenLength of src in bytes
Returns
Number of decoded bytes