]> git.ipfire.org Git - thirdparty/squid.git/blob - include/base64.h
Enable source-formatting tools to collapse multiple whitelines in the source to one.
[thirdparty/squid.git] / include / base64.h
1 #ifndef _SQUID_BASE64_H
2 #define _SQUID_BASE64_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 // Decoding functions
9
10 /// Calculate the decoded length of a given nul-terminated encoded string.
11 /// NULL pointer and empty strings are accepted, result is zero.
12 /// Any return value <= zero means no decoded result can be produced.
13 extern int base64_decode_len(const char *encodedData);
14
15 /// Decode a base-64 encoded blob into a provided buffer.
16 /// Will not terminate the resulting string.
17 /// In-place decoding overlap is supported if result is equal or earlier that the source pointer.
18 ///
19 /// \return number of bytes filled in result.
20 extern int base64_decode(char *result, unsigned int result_max_size, const char *encoded);
21
22
23 // Encoding functions
24
25 /// Calculate the buffer size required to hold the encoded form of
26 /// a string of length 'decodedLen' including all terminator bytes.
27 extern int base64_encode_len(int decodedLen);
28
29 /// Base-64 encode a string into a given buffer.
30 /// Will not terminate the resulting string.
31 /// \return the number of bytes filled in result.
32 extern int base64_encode(char *result, int result_max_size, const char *data, int data_size);
33
34 /// Base-64 encode a string into a given buffer.
35 /// Will terminate the resulting string.
36 /// \return the number of bytes filled in result. Including the terminator.
37 extern int base64_encode_str(char *result, int result_max_size, const char *data, int data_size);
38
39 // Old encoder. Now a wrapper for the new. Takes a binary array of known length.
40 // Output is presented in a static buffer which will only remain valid until next call.
41 // Ensures a nul-terminated result. Will always return non-NULL.
42 extern const char *base64_encode_bin(const char *data, int len);
43
44 // Old encoder. Now a wrapper for the new.
45 // Output is presented in a static buffer which will only remain valid until next call.
46 // Ensures a nul-terminated result. Will always return non-NULL.
47 extern const char *old_base64_encode(const char *decoded);
48
49
50 #ifdef __cplusplus
51 }
52 #endif
53 #endif /* _SQUID_BASE64_H */