| 52 | } |
| 53 | |
| 54 | size_t base32_data_size(const char *str, size_t strlen) |
| 55 | { |
| 56 | /* 8 chars == 5 bytes, round up to avoid overflow even though |
| 57 | * not required for well-formed strings. */ |
| 58 | size_t max = (strlen + 7) / 8 * 5, padding = 0; |
| 59 | |
| 60 | /* Count trailing padding bytes. */ |
| 61 | while (strlen && str[strlen-1] == base32_chars[32] && padding < 6) { |
| 62 | strlen--; |
| 63 | padding++; |
| 64 | } |
| 65 | |
| 66 | return max - (padding * 5 + 7) / 8; |
| 67 | } |
| 68 | |
| 69 | static bool decode_8_chars(const char c[8], beint64_t *res, int *bytes) |
| 70 | { |
no outgoing calls