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

Function encrypted_decode

plugins/offers.c:520–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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