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

Function b12_string_to_data

common/bolt12.c:112–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112const u8 *b12_string_to_data(const tal_t *ctx,
113 const char *str,
114 size_t str_len,
115 const char *hrp_expected,
116 size_t *dlen,
117 const char **fail)
118{
119 char *hrp;
120 u8 *data;
121 char *bech32;
122 size_t bech32_len;
123 bool have_plus = false;
124
125 /* First we collapse +\s*, except at start/end. */
126 bech32 = tal_arr(tmpctx, char, str_len);
127 bech32_len = 0;
128 for (size_t i = 0; i < str_len; i++) {
129 if (i != 0 && i+1 != str_len && !have_plus && str[i] == '+') {
130 have_plus = true;
131 continue;
132 }
133 if (have_plus && cisspace(str[i]))
134 continue;
135 have_plus = false;
136 bech32[bech32_len++] = str[i];
137 }
138
139 if (have_plus) {
140 *fail = tal_fmt(ctx, "unfinished string");
141 return NULL;
142 }
143
144 if (!from_bech32_charset(ctx, bech32, bech32_len, &hrp, &data)) {
145 *fail = tal_fmt(ctx, "invalid bech32 string");
146 return NULL;
147 }
148 if (!streq(hrp, hrp_expected)) {
149 *fail = tal_fmt(ctx, "unexpected prefix %s", hrp);
150 data = tal_free(data);
151 } else
152 *dlen = tal_bytelen(data);
153
154 tal_free(hrp);
155 return data;
156}
157
158char *offer_encode(const tal_t *ctx, const struct tlv_offer *offer_tlv)
159{

Callers 9

runFunction · 0.85
LLVMFuzzerCustomMutatorFunction · 0.85
payer_proof_decodeFunction · 0.85
offer_decodeFunction · 0.85
invrequest_decodeFunction · 0.85
invoice_decode_minimalFunction · 0.85
generate_invalid_vectorsFunction · 0.85
mainFunction · 0.85

Calls 4

cisspaceFunction · 0.85
tal_freeFunction · 0.85
tal_bytelenFunction · 0.85
from_bech32_charsetFunction · 0.70

Tested by 2

generate_invalid_vectorsFunction · 0.68
mainFunction · 0.68