1 /* CC0 (Public domain) - see LICENSE file for details */
2 #ifndef CCAN_STR_BASE32_H
3 #define CCAN_STR_BASE32_H
9 * base32_decode - Unpack a base32 string.
10 * @str: the base32 string
11 * @slen: the length of @str
12 * @buf: the buffer to write the data into
13 * @bufsize: the length of @buf
15 * Returns false if there are any characters which aren't valid encodings
16 * or the string wasn't the right length for @bufsize.
19 * unsigned char data[20];
21 * if (!base32_decode(argv[1], strlen(argv[1]), data, 20))
22 * printf("String is malformed!\n");
24 bool base32_decode(const char *str, size_t slen, void *buf, size_t bufsize);
27 * base32_encode - Create a nul-terminated base32 string
28 * @buf: the buffer to read the data from
29 * @bufsize: the length of @buf
30 * @dest: the string to fill
31 * @destsize: the max size of the string
33 * Returns true if the string, including terminator, fits in @destsize;
36 * unsigned char buf[] = { 'f', 'o' };
39 * if (!base32_encode(buf, sizeof(buf), str, sizeof(str)))
42 bool base32_encode(const void *buf, size_t bufsize, char *dest, size_t destsize);
45 * base32_str_size - Calculate how big a nul-terminated base32 string is
46 * @bytes: bytes of data to represent
49 * unsigned char buf[] = { 'f', 'o' };
50 * char str[base32_str_size(sizeof(buf))];
52 * base32_encode(buf, sizeof(buf), str, sizeof(str));
54 size_t base32_str_size(size_t bytes);
57 * base32_data_size - Calculate how many bytes of data in a base32 string
59 * @strlen: the length of str to examine.
62 * const char str[] = "MZXQ====";
63 * unsigned char buf[base32_data_size(str, strlen(str))];
65 * base32_decode(str, strlen(str), buf, sizeof(buf));
67 size_t base32_data_size(const char *str, size_t strlen);
70 * base32_chars - the encoding/decoding array to use.
72 * It must be at least 33 characters long, representing 32 values and
73 * the pad value. The default array is "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=".
75 extern const char *base32_chars;
77 #endif /* CCAN_STR_BASE32_H */