DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
base64.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file base64.h
6 * @brief Base64 encoder/decoder.
7 *
8 * On Arduino (ESP32) targets, delegates to mbedtls_base64_encode/decode()
9 * from the ESP-IDF mbedTLS bundle — same SDK path as SHA-1.
10 *
11 * On native (x86) test targets, uses a portable software implementation so
12 * unit tests run without mbedTLS installed.
13 *
14 * Used to encode the SHA-1 digest in the WebSocket handshake response
15 * (RFC 6455 §4.2.2) and to decode Basic Auth credentials (RFC 7617).
16 *
17 * @author Douglas Quigg (dstroy0)
18 * @date 2026
19 */
20
21#ifndef DETERMINISTICESPASYNCWEBSERVER_BASE64_H
22#define DETERMINISTICESPASYNCWEBSERVER_BASE64_H
23
24#include <stddef.h>
25#include <stdint.h>
26
27/**
28 * @brief Encode @p src_len bytes of @p src as Base64.
29 *
30 * Writes a null-terminated string into @p dst. @p dst must be at least
31 * `((src_len + 2) / 3) * 4 + 1` bytes.
32 *
33 * @param src Input bytes.
34 * @param src_len Number of input bytes.
35 * @param dst Output buffer (null-terminated Base64 string).
36 */
37void base64_encode(const uint8_t *src, size_t src_len, char *dst);
38
39/**
40 * @brief Decode a null-terminated Base64 string.
41 *
42 * Writes decoded bytes into @p dst. @p dst must be at least
43 * `(strlen(src) / 4) * 3` bytes. Returns the number of decoded bytes.
44 * Returns 0 on invalid input.
45 *
46 * @param src Null-terminated Base64 input string.
47 * @param dst Output byte buffer.
48 * @return Number of bytes written to @p dst, or 0 on error.
49 */
50size_t base64_decode(const char *src, uint8_t *dst);
51
52#endif
void base64_encode(const uint8_t *src, size_t src_len, char *dst)
Encode src_len bytes of src as Base64.
Definition base64.cpp:23
size_t base64_decode(const char *src, uint8_t *dst)
Decode a null-terminated Base64 string.
Definition base64.cpp:31