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

Function to_zbase32

lightningd/signmessage.c:24–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22static 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, };
23
24static const char *to_zbase32(const tal_t *ctx, const u8 *msg, size_t srclen)
25{
26 size_t outlen;
27 char *out = tal_arr(ctx, char, (srclen * 8 + 4) / 5 + 1);
28
29 outlen = 0;
30 if (!bech32_convert_bits((uint8_t *)out, &outlen, 5, msg, srclen, 8, true))
31 return tal_free(out);
32 assert(outlen < tal_bytelen(out));
33 for (size_t i = 0; i < outlen; i++)
34 out[i] = zbase32_chars[(unsigned)out[i]];
35 out[outlen] = '\0';
36 return out;
37}
38
39static const u8 *from_zbase32(const tal_t *ctx, const char *msg)
40{

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