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

Function encrypted_decode

plugins/offers.c:522–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520};
521
522static u8 *encrypted_decode(const tal_t *ctx, const char *str, const char **fail)
523{
524 if (strlen(str) < 8) {
525 *fail = tal_fmt(ctx, "invalid payload");
526 return NULL;
527 }
528
529 size_t hrp_maxlen = strlen(str) - 6;
530 char *hrp = tal_arr(ctx, char, hrp_maxlen);
531
532 size_t data_maxlen = strlen(str) - 8;
533 u5 *data = tal_arr(ctx, u5, data_maxlen);
534 size_t datalen = 0;
535
536 if (bech32_decode(hrp, data, &datalen, str, (size_t)-1)
537 == BECH32_ENCODING_NONE) {
538 *fail = tal_fmt(ctx, "invalid bech32 encoding");
539 goto fail;
540 }
541
542 if (!streq(hrp, "clnemerg")) {
543 *fail = tal_fmt(ctx, "hrp should be `clnemerg`");
544 goto fail;
545 }
546 u8 *data8bit = tal_arr(data, u8, 0);
547 if (!bech32_pull_bits(&data8bit, data, datalen*5)) {
548 *fail = tal_fmt(ctx, "invalid bech32 padding");
549 goto fail;
550 }
551
552 return data8bit;
553fail:
554 tal_free(data);
555 return NULL;
556}
557
558enum likely_type {
559 LIKELY_BOLT12_OFFER,

Callers 1

param_decodableFunction · 0.85

Calls 3

bech32_pull_bitsFunction · 0.85
tal_freeFunction · 0.85
bech32_decodeFunction · 0.50

Tested by

no test coverage detected