aboutsummaryrefslogtreecommitdiff
path: root/tools/server/base64.h
blob: 41277d1494f8fd4b4818f1f6686e2ac1a50af723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef FFWD_BASE64_H
#define FFWD_BASE64_H

#include <stddef.h>

/* Standard base64 (with '=' padding). */

/* Number of base64 characters for n input bytes, excluding any NUL.
 * Aborts (die-on-OOM) if n is so large the length would overflow. */
size_t base64_encoded_len(size_t n);

/* Encode n bytes of src as base64 into dst, writing exactly base64_encoded_len(n)
 * bytes and no NUL terminator; dst must have room for that many bytes. */
void base64_encode_to(char *dst, const unsigned char *src, size_t n);

/* Convenience wrapper: returns a NUL-terminated heap string the caller frees;
 * die-on-OOM, so it never returns NULL. */
char *base64_encode(const unsigned char *src, size_t n);

#endif /* FFWD_BASE64_H */