Compy 0.2.0
A lightweight RTSP 1.0 server library for embedded systems
Loading...
Searching...
No Matches
base64.h File Reference

Base64 encoding and decoding (RFC 4648). More...

#include <stddef.h>
#include <unistd.h>
#include <compy/priv/compiler_attrs.h>
Include dependency graph for base64.h:

Go to the source code of this file.

Functions

ssize_t compy_base64_encode (const void *data, size_t len, char *out, size_t out_max) COMPY_PRIV_MUST_USE
 Encodes binary data to base64.
 
ssize_t compy_base64_decode (const char *b64, size_t len, void *out, size_t out_max) COMPY_PRIV_MUST_USE
 Decodes a base64 string to binary.
 

Detailed Description

Base64 encoding and decoding (RFC 4648).

Self-contained implementation with no external dependencies. This is a private header; do not include directly from application code.

Function Documentation

◆ compy_base64_decode()

ssize_t compy_base64_decode ( const char *  b64,
size_t  len,
void *  out,
size_t  out_max 
)

Decodes a base64 string to binary.

Parameters
[in]b64The base64-encoded string.
[in]lenLength of b64 (excluding any null terminator).
[out]outOutput buffer for decoded binary data.
[in]out_maxSize of out. Must be at least (len / 4) * 3 bytes.
Precondition
out != NULL
Returns
Number of bytes decoded, or -1 on invalid input or if out_max is too small.

◆ compy_base64_encode()

ssize_t compy_base64_encode ( const void *  data,
size_t  len,
char *  out,
size_t  out_max 
)

Encodes binary data to base64.

Parameters
[in]dataInput binary data.
[in]lenLength of data.
[out]outOutput buffer for the base64 string (null-terminated).
[in]out_maxSize of out. Must be at least ((len + 2) / 3) * 4 + 1 bytes.
Precondition
out != NULL
Returns
Number of characters written (excluding null terminator), or -1 if out_max is too small.