DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
base64.h File Reference

Base64 encoder/decoder. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

void base64_encode (const uint8_t *src, size_t src_len, char *dst)
 Encode src_len bytes of src as Base64.
 
size_t base64_decode (const char *src, uint8_t *dst)
 Decode a null-terminated Base64 string.
 

Detailed Description

Base64 encoder/decoder.

On Arduino (ESP32) targets, delegates to mbedtls_base64_encode/decode() from the ESP-IDF mbedTLS bundle — same SDK path as SHA-1.

On native (x86) test targets, uses a portable software implementation so unit tests run without mbedTLS installed.

Used to encode the SHA-1 digest in the WebSocket handshake response (RFC 6455 §4.2.2) and to decode Basic Auth credentials (RFC 7617).

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file base64.h.

Function Documentation

◆ base64_encode()

void base64_encode ( const uint8_t *  src,
size_t  src_len,
char *  dst 
)

Encode src_len bytes of src as Base64.

Writes a null-terminated string into dst. dst must be at least ((src_len + 2) / 3) * 4 + 1 bytes.

Parameters
srcInput bytes.
src_lenNumber of input bytes.
dstOutput buffer (null-terminated Base64 string).

Definition at line 23 of file base64.cpp.

◆ base64_decode()

size_t base64_decode ( const char *  src,
uint8_t *  dst 
)

Decode a null-terminated Base64 string.

Writes decoded bytes into dst. dst must be at least (strlen(src) / 4) * 3 bytes. Returns the number of decoded bytes. Returns 0 on invalid input.

Parameters
srcNull-terminated Base64 input string.
dstOutput byte buffer.
Returns
Number of bytes written to dst, or 0 on error.

Definition at line 31 of file base64.cpp.