Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / base64.h
1 #ifndef _IPXE_BASE64_H
2 #define _IPXE_BASE64_H
3
4 /** @file
5  *
6  * Base64 encoding
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #include <stdint.h>
13 #include <string.h>
14
15 /**
16  * Calculate length of base64-encoded data
17  *
18  * @v raw_len           Raw data length
19  * @ret encoded_len     Encoded string length (excluding NUL)
20  */
21 static inline size_t base64_encoded_len ( size_t raw_len ) {
22         return ( ( ( raw_len + 3 - 1 ) / 3 ) * 4 );
23 }
24
25 /**
26  * Calculate maximum length of base64-decoded string
27  *
28  * @v encoded           Encoded string
29  * @v max_raw_len       Maximum length of raw data
30  *
31  * Note that the exact length of the raw data cannot be known until
32  * the string is decoded.
33  */
34 static inline size_t base64_decoded_max_len ( const char *encoded ) {
35         return ( ( ( strlen ( encoded ) + 4 - 1 ) / 4 ) * 3 );
36 }
37
38 extern void base64_encode ( const uint8_t *raw, size_t len, char *encoded );
39 extern int base64_decode ( const char *encoded, uint8_t *raw );
40
41 #endif /* _IPXE_BASE64_H */