If pad is false, we discard any bits which don't fit in the last byte. * Otherwise we add an extra byte. Returns error string or NULL on success. */
| 39 | /* If pad is false, we discard any bits which don't fit in the last byte. |
| 40 | * Otherwise we add an extra byte. Returns error string or NULL on success. */ |
| 41 | static const char *pull_bits(struct hash_u5 *hu5, |
| 42 | const u5 **data, size_t *data_len, |
| 43 | void *dst, size_t nbits, |
| 44 | bool pad) |
| 45 | { |
| 46 | size_t n5 = nbits / 5; |
| 47 | size_t len = 0; |
| 48 | |
| 49 | if (nbits % 5) |
| 50 | n5++; |
| 51 | |
| 52 | if (*data_len < n5) |
| 53 | return "truncated"; |
| 54 | if (!bech32_convert_bits(dst, &len, 8, *data, n5, 5, pad)) |
| 55 | return "non-zero trailing bits"; |
| 56 | if (hu5) |
| 57 | hash_u5(hu5, *data, n5); |
| 58 | *data += n5; |
| 59 | *data_len -= n5; |
| 60 | |
| 61 | return NULL; |
| 62 | } |
| 63 | |
| 64 | /* Helper for pulling a variable-length big-endian int. */ |
| 65 | static const char *pull_uint(struct hash_u5 *hu5, |
no test coverage detected