core-lightning/common/base32.c
Rusty Russell d5e4d52563 common/base32: make this a simple tal-wrapper around ccan/base32.
And use it in wireaddr.

We fix up the double '.onion' in the test case, which seems like an error?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-10 02:28:44 +00:00

25 lines
636 B
C

#include <ccan/str/base32/base32.h>
#include <common/base32.h>
/* We want lower-case conversion please */
static const char base32_lower[] = "abcdefghijklmnopqrstuvwxyz234567=";
char *b32_encode(const tal_t *ctx, const void *data, size_t len)
{
char *str = tal_arr(ctx, char, base32_str_size(len));
base32_chars = base32_lower;
base32_encode(data, len, str, tal_len(str));
return str;
}
u8 *b32_decode(const tal_t *ctx, const char *str, size_t len)
{
u8 *ret = tal_arr(ctx, u8, base32_data_size(str, len));
base32_chars = base32_lower;
if (!base32_decode(str, len, ret, tal_len(ret)))
return tal_free(ret);
return ret;
}