All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
base64.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef _FR_BASE64_H
17 #define _FR_BASE64_H
18 /**
19  * $Id: ed67ead06c8dc02a1fe3c92c12ed09ede8de6de8 $
20  *
21  * @file include/base64.h
22  * @brief Encode and decode data in base64 format.
23  *
24  * @author Simon Josefsson
25  * @copyright 2004, 2005, 2006 Free Software Foundation, Inc.
26  */
27 RCSIDH(base64_h, "$Id: ed67ead06c8dc02a1fe3c92c12ed09ede8de6de8 $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 /* This uses that the expression (n+(k-1))/k means the smallest
37  integer >= n/k, i.e., the ceiling of n/k. */
38 #define FR_BASE64_ENC_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
39 #define FR_BASE64_DEC_LENGTH(inlen) ((3 * (inlen / 4)) + 2)
40 
41 bool fr_is_base64(char c);
42 
43 size_t fr_base64_encode(char *out, size_t outlen, uint8_t const *in, size_t inlen);
44 
45 ssize_t fr_base64_decode(uint8_t *out, size_t outlen, char const *in, size_t inlen);
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 #endif /* _FR_BASE64_H */
#define RCSIDH(h, id)
Definition: build.h:136
ssize_t fr_base64_decode(uint8_t *out, size_t outlen, char const *in, size_t inlen)
Definition: base64.c:251
bool fr_is_base64(char c)
Check if char is in Base64 alphabet.
Definition: base64.c:223
size_t fr_base64_encode(char *out, size_t outlen, uint8_t const *in, size_t inlen)
Base 64 encode binary data.
Definition: base64.c:44