Rev 178 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 178 | Rev 186 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | 10 | ||
11 | size_t base64_encode (char *dest, const char *source, size_t source_len) |
11 | size_t base64_encode (char *dest, const char *source, size_t source_len) |
12 | { |
12 | { |
13 | // encode a string in its base64 equivalent. It is up to the caller to ensure |
13 | // encode a string in its base64 equivalent. It is up to the caller to ensure |
14 | // that dest is large enough to contain the base64 representation of source. |
14 | // that dest is large enough to contain the base64 representation of source. |
15 | // Typically, a 4/3 size ratio is needed (i.e. when source is 30 bytes long, |
15 | // Typically, a 4/3+4 size ratio is needed (i.e. when source is 30 bytes long, |
16 | // dest should be large enough to contain |
16 | // dest should be large enough to contain 44 bytes, the last 4 being padding). |
17 | // When finished, return the length of the decoded data. |
17 | // When finished, return the length of the decoded data. |
18 | 18 | ||
19 | static const char char_values[64 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
19 | static const char char_values[64 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
20 | 20 | ||
21 | unsigned char bytes[3]; |
21 | unsigned char bytes[3]; |