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

Function to_zbase32

lightningd/signmessage.c:21–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19static const u8 zbase32_revchars[]={ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 18, 255, 25, 26, 27, 30, 29, 7, 31, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 24, 1, 12, 3, 8, 5, 6, 28, 21, 9, 10, 255, 11, 2, 16, 13, 14, 4, 22, 17, 19, 255, 20, 15, 0, 23, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, };
20
21static const char *to_zbase32(const tal_t *ctx, const u8 *msg, size_t srclen)
22{
23 size_t outlen;
24 char *out = tal_arr(ctx, char, (srclen * 8 + 4) / 5 + 1);
25
26 outlen = 0;
27 if (!bech32_convert_bits((uint8_t *)out, &outlen, 5, msg, srclen, 8, true))
28 return tal_free(out);
29 assert(outlen < tal_bytelen(out));
30 for (size_t i = 0; i < outlen; i++)
31 out[i] = zbase32_chars[(unsigned)out[i]];
32 out[outlen] = '\0';
33 return out;
34}
35
36static const u8 *from_zbase32(const tal_t *ctx, const char *msg)
37{

Callers 1

json_signmessageFunction · 0.85

Calls 3

bech32_convert_bitsFunction · 0.85
tal_freeFunction · 0.85
tal_bytelenFunction · 0.85

Tested by

no test coverage detected