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

Function b12_string_to_data

common/bolt12.c:323–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321}
322
323const u8 *b12_string_to_data(const tal_t *ctx,
324 const char *str,
325 size_t str_len,
326 const char *hrp_expected,
327 size_t *dlen,
328 const char **fail)
329{
330 char *hrp;
331 u8 *data;
332 char *bech32;
333 size_t bech32_len;
334 bool have_plus = false;
335
336 /* First we collapse +\s*, except at start/end. */
337 bech32 = tal_arr(tmpctx, char, str_len);
338 bech32_len = 0;
339 for (size_t i = 0; i < str_len; i++) {
340 if (i != 0 && i+1 != str_len && !have_plus && str[i] == '+') {
341 have_plus = true;
342 continue;
343 }
344 if (have_plus && cisspace(str[i]))
345 continue;
346 have_plus = false;
347 bech32[bech32_len++] = str[i];
348 }
349
350 if (have_plus) {
351 *fail = tal_fmt(ctx, "unfinished string");
352 return NULL;
353 }
354
355 if (!from_bech32_charset(ctx, bech32, bech32_len, &hrp, &data)) {
356 *fail = tal_fmt(ctx, "invalid bech32 string");
357 return NULL;
358 }
359 if (!streq(hrp, hrp_expected)) {
360 *fail = tal_fmt(ctx, "unexpected prefix %s", hrp);
361 data = tal_free(data);
362 } else
363 *dlen = tal_bytelen(data);
364
365 tal_free(hrp);
366 return data;
367}
368
369char *offer_encode(const tal_t *ctx, const struct tlv_offer *offer_tlv)
370{

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