MCPcopy Create free account
hub / github.com/ElementsProject/lightning / pull_bits

Function pull_bits

common/bolt11.c:41–62  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

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. */
41static 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. */
65static const char *pull_uint(struct hash_u5 *hu5,

Callers 4

pull_uintFunction · 0.85
pull_allFunction · 0.85
pull_expected_lengthFunction · 0.85
bolt11_decodeFunction · 0.85

Calls 2

bech32_convert_bitsFunction · 0.85
hash_u5Class · 0.70

Tested by

no test coverage detected