iPXE
base64.h
Go to the documentation of this file.
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_OR_UBDL );
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 size_t base64_encode ( const void *raw, size_t raw_len, char *data,
39  size_t len );
40 extern int base64_decode ( const char *encoded, void *data, size_t len );
41 
42 #endif /* _IPXE_BASE64_H */
int base64_decode(const char *encoded, void *data, size_t len)
Base64-decode string.
Definition: base64.c:91
static size_t base64_encoded_len(size_t raw_len)
Calculate length of base64-encoded data.
Definition: base64.h:21
static size_t base64_decoded_max_len(const char *encoded)
Calculate maximum length of base64-decoded string.
Definition: base64.h:34
static size_t raw_len
Definition: base16.h:50
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
__be32 raw[7]
Definition: CIB_PRM.h:28
size_t base64_encode(const void *raw, size_t raw_len, char *data, size_t len)
Base64-encode data.
Definition: base64.c:51
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
String functions.