base64.h
1 /*
2  * SPDX-FileCopyrightText: 2014 Hochschule für Angewandte Wissenschaften Hamburg (HAW)
3  * SPDX-FileCopyrightText: 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.de>
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
19 #include <stddef.h> /* for size_t */
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define BASE64_SUCCESS (0)
26 #define BASE64_ERROR_BUFFER_OUT (-1)
27 #define BASE64_ERROR_BUFFER_OUT_SIZE (-2)
28 #define BASE64_ERROR_DATA_IN (-3)
29 #define BASE64_ERROR_DATA_IN_SIZE (-4)
38 static inline size_t base64_estimate_decode_size(size_t base64_in_size)
39 {
40  return (((base64_in_size + 3) / 4) * 3);
41 }
42 
50 static inline size_t base64_estimate_encode_size(size_t data_in_size)
51 {
52  return (4 * ((data_in_size + 2) / 3));
53 }
54 
72 int base64_encode(const void *data_in, size_t data_in_size,
73  void *base64_out, size_t *base64_out_size);
74 
98 int base64url_encode(const void *data_in, size_t data_in_size,
99  void *base64_out, size_t *base64_out_size);
100 
119 int base64_decode(const void *base64_in, size_t base64_in_size,
120  void *data_out, size_t *data_out_size);
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
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:50
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:38