]> mj.ucw.cz Git - libucw.git/blob - ucw/base64.h
Macros: CLAMP now accepts arbitrary types, not only ints
[libucw.git] / ucw / base64.h
1 /*
2  *      UCW Library -- Base 64 Encoding & Decoding
3  *
4  *      (c) 2002, Robert Spalek <robert@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifdef CONFIG_UCW_CLEAN_ABI
11 #define base64_decode ucw_base64_decode
12 #define base64_encode ucw_base64_encode
13 #endif
14
15 /**
16  * Encodes @len bytes of data pointed to by @src by base64 encoding.
17  * Stores them in @dest and returns the number of bytes the output
18  * takes.
19  */
20 uint base64_encode(byte *dest, const byte *src, uint len);
21 /**
22  * Decodes @len bytes of data pointed to by @src from base64 encoding.
23  * All invalid characters are ignored. The result is stored into @dest
24  * and length of the result is returned.
25  */
26 uint base64_decode(byte *dest, const byte *src, uint len);
27
28 /**
29  * Use this macro to calculate @base64_encode() output buffer size.
30  */
31 #define BASE64_ENC_LENGTH(x) (((x)+2)/3 *4)
32
33 /*
34  * When called for BASE64_IN_CHUNK-byte chunks, the result will be
35  * always BASE64_OUT_CHUNK bytes long. If a longer block is split
36  * to such chunks, the result will be identical.
37  */
38 #define BASE64_IN_CHUNK 3 /** Size of chunk on the un-encoded side. **/
39 #define BASE64_OUT_CHUNK 4 /** Size of chunk on the encoded side. **/
40