Browse Source
These were so far only used for bolt11 construction, but we'll need them for the DNS seed as well, so here we just pull them out into their own unit and prefix them. Signed-off-by: Christian Decker <decker.christian@gmail.com>ppa-0.6.1
Christian Decker
7 years ago
8 changed files with 49 additions and 28 deletions
@ -0,0 +1,25 @@ |
|||
#include "bech32_util.h" |
|||
#include <ccan/tal/tal.h> |
|||
|
|||
static u8 get_bit(const u8 *src, size_t bitoff) |
|||
{ |
|||
return ((src[bitoff / 8] >> (7 - (bitoff % 8))) & 1); |
|||
} |
|||
|
|||
void bech32_push_bits(u5 **data, const void *src, size_t nbits) |
|||
{ |
|||
size_t i, b; |
|||
size_t data_len = tal_len(*data); |
|||
|
|||
for (i = 0; i < nbits; i += b) { |
|||
tal_resize(data, data_len+1); |
|||
(*data)[data_len] = 0; |
|||
for (b = 0; b < 5; b++) { |
|||
(*data)[data_len] <<= 1; |
|||
/* If we need bits we don't have, zero */ |
|||
if (i+b < nbits) |
|||
(*data)[data_len] |= get_bit(src, i+b); |
|||
} |
|||
data_len++; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
#ifndef LIGHTNING_COMMON_BECH32_UTIL_H |
|||
#define LIGHTNING_COMMON_BECH32_UTIL_H |
|||
#include "config.h" |
|||
|
|||
#include <ccan/short_types/short_types.h> |
|||
#include <common/hash_u5.h> |
|||
|
|||
/**
|
|||
* Push the bytes in src in 5 bit format onto the end of data. |
|||
*/ |
|||
void bech32_push_bits(u5 **data, const void *src, size_t nbits); |
|||
|
|||
#endif /* LIGHTNING_COMMON_BECH32_UTIL_H */ |
Loading…
Reference in new issue