2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2018-05-10 01:18:24 +02:00
|
|
|
#include <ccan/str/base32/base32.h>
|
2018-05-10 01:18:19 +02:00
|
|
|
#include <common/base32.h>
|
|
|
|
|
2018-05-10 01:18:24 +02:00
|
|
|
/* We want lower-case conversion please */
|
|
|
|
static const char base32_lower[] = "abcdefghijklmnopqrstuvwxyz234567=";
|
2018-05-10 01:18:19 +02:00
|
|
|
|
2018-05-10 01:18:24 +02:00
|
|
|
char *b32_encode(const tal_t *ctx, const void *data, size_t len)
|
2018-05-10 01:18:19 +02:00
|
|
|
{
|
2018-05-10 01:18:24 +02:00
|
|
|
char *str = tal_arr(ctx, char, base32_str_size(len));
|
2018-05-10 01:18:19 +02:00
|
|
|
|
2018-05-10 01:18:24 +02:00
|
|
|
base32_chars = base32_lower;
|
2018-07-28 08:00:16 +02:00
|
|
|
base32_encode(data, len, str, tal_count(str));
|
2018-05-10 01:18:24 +02:00
|
|
|
return str;
|
|
|
|
}
|
2018-05-10 01:18:19 +02:00
|
|
|
|
2018-05-10 01:18:24 +02:00
|
|
|
u8 *b32_decode(const tal_t *ctx, const char *str, size_t len)
|
2018-05-10 01:18:19 +02:00
|
|
|
{
|
2018-05-10 01:18:24 +02:00
|
|
|
u8 *ret = tal_arr(ctx, u8, base32_data_size(str, len));
|
|
|
|
|
|
|
|
base32_chars = base32_lower;
|
2018-07-28 08:00:16 +02:00
|
|
|
if (!base32_decode(str, len, ret, tal_count(ret)))
|
2018-05-10 01:18:24 +02:00
|
|
|
return tal_free(ret);
|
|
|
|
return ret;
|
2018-05-10 01:18:19 +02:00
|
|
|
}
|