Pico Headers
|
A simple Base64 encoding/decoding library. More...
#include <stddef.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) | |
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) | |
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) | |
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) | |
A simple Base64 encoding/decoding library.
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.
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.
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)
len | The length of the array of bytes |
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)
src | The string to decode. This is only used to determine padding and is not traversed |
len | The length of the encoded (src ) string |
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)
dst | Encoded character (destination) buffer |
src | Byte array to be encoded |
len | Length of src in bytes |
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)
dst | Decoded byte array (destination) |
src | Character array to be decoded |
len | Length of src in bytes |