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

Function pull_bits

common/bolt11.c:57–77  ·  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 */

Source from the content-addressed store, hash-verified

55/* If pad is false, we discard any bits which don't fit in the last byte.
56 * Otherwise we add an extra byte */
57static bool pull_bits(struct hash_u5 *hu5,
58 u5 **data, size_t *data_len, void *dst, size_t nbits,
59 bool pad)
60{
61 size_t n5 = nbits / 5;
62 size_t len = 0;
63
64 if (nbits % 5)
65 n5++;
66
67 if (*data_len < n5)
68 return false;
69 if (!bech32_convert_bits(dst, &len, 8, *data, n5, 5, pad))
70 return false;
71 if (hu5)
72 hash_u5(hu5, *data, n5);
73 *data += n5;
74 *data_len -= n5;
75
76 return true;
77}
78
79/* For pulling fields where we should have checked it will succeed already. */
80#ifndef NDEBUG

Callers 2

pull_uintFunction · 0.85
bolt11_decodeFunction · 0.85

Calls 2

bech32_convert_bitsFunction · 0.85
hash_u5Class · 0.70

Tested by

no test coverage detected