Loading...
Searching...
No Matches
base64.h
1/*
2 * Copyright (C) 2014 Hochschule für Angewandte Wissenschaften Hamburg (HAW)
3 * Copyright (C) 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.de>
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
20#ifndef BASE64_H
21#define BASE64_H
22
23#include <stddef.h> /* for size_t */
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define BASE64_SUCCESS (0)
30#define BASE64_ERROR_BUFFER_OUT (-1)
31#define BASE64_ERROR_BUFFER_OUT_SIZE (-2)
32#define BASE64_ERROR_DATA_IN (-3)
33#define BASE64_ERROR_DATA_IN_SIZE (-4)
42static inline size_t base64_estimate_decode_size(size_t base64_in_size)
43{
44 return (((base64_in_size + 3) / 4) * 3);
45}
46
54static inline size_t base64_estimate_encode_size(size_t data_in_size)
55{
56 return (4 * ((data_in_size + 2) / 3));
57}
58
76int base64_encode(const void *data_in, size_t data_in_size,
77 void *base64_out, size_t *base64_out_size);
78
102int base64url_encode(const void *data_in, size_t data_in_size,
103 void *base64_out, size_t *base64_out_size);
104
123int base64_decode(const void *base64_in, size_t base64_in_size,
124 void *data_out, size_t *data_out_size);
125
126#ifdef __cplusplus
127}
128#endif
129
131#endif /* BASE64_H */
int base64_decode(const void *base64_in, size_t base64_in_size, void *data_out, size_t *data_out_size)
Decodes a given base64 string and save the result to the given destination.
static size_t base64_estimate_encode_size(size_t data_in_size)
Estimates the length of the resulting string after encoding data_in_size bytes into base64.
Definition base64.h:54
int base64url_encode(const void *data_in, size_t data_in_size, void *base64_out, size_t *base64_out_size)
Encodes a given datum to base64 with URL and Filename Safe Alphabet and save the result to the given ...
int base64_encode(const void *data_in, size_t data_in_size, void *base64_out, size_t *base64_out_size)
Encodes a given datum to base64 and save the result to the given destination.
static size_t base64_estimate_decode_size(size_t base64_in_size)
Estimates the amount of bytes needed for decoding base64_in_size characters from base64.
Definition base64.h:42