]>
git.ipfire.org Git - thirdparty/squid.git/blob - include/base64.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef _SQUID_BASE64_H
10 #define _SQUID_BASE64_H
18 /// Calculate the decoded length of a given nul-terminated encoded string.
19 /// NULL pointer and empty strings are accepted, result is zero.
20 /// Any return value <= zero means no decoded result can be produced.
21 extern int base64_decode_len(const char *encodedData
);
23 /// Decode a base-64 encoded blob into a provided buffer.
24 /// Will not terminate the resulting string.
25 /// In-place decoding overlap is supported if result is equal or earlier that the source pointer.
27 /// \return number of bytes filled in result.
28 extern int base64_decode(char *result
, unsigned int result_max_size
, const char *encoded
);
32 /// Calculate the buffer size required to hold the encoded form of
33 /// a string of length 'decodedLen' including all terminator bytes.
34 extern int base64_encode_len(int decodedLen
);
36 /// Base-64 encode a string into a given buffer.
37 /// Will not terminate the resulting string.
38 /// \return the number of bytes filled in result.
39 extern int base64_encode(char *result
, int result_max_size
, const char *data
, int data_size
);
41 /// Base-64 encode a string into a given buffer.
42 /// Will terminate the resulting string.
43 /// \return the number of bytes filled in result. Including the terminator.
44 extern int base64_encode_str(char *result
, int result_max_size
, const char *data
, int data_size
);
46 // Old encoder. Now a wrapper for the new. Takes a binary array of known length.
47 // Output is presented in a static buffer which will only remain valid until next call.
48 // Ensures a nul-terminated result. Will always return non-NULL.
49 extern const char *base64_encode_bin(const char *data
, int len
);
51 // Old encoder. Now a wrapper for the new.
52 // Output is presented in a static buffer which will only remain valid until next call.
53 // Ensures a nul-terminated result. Will always return non-NULL.
54 extern const char *old_base64_encode(const char *decoded
);
59 #endif /* _SQUID_BASE64_H */