mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
Init commit to be able to create a tor static service on the fly.
We want to have a static Tor service created from a blob bound to our node on cmdline Changelog-added: persistent Tor address support Changelog-added: allow the Tor inbound service port differ from 9735 Signed-off-by: Saibato <saibato.naga@pm.me> Add base64 encode/decode to common We need this to encode the blob for the tor service Signed-off-by: Saibato <saibato.naga@pm.me>
This commit is contained in:
committed by
Christian Decker
parent
99ff86f6fe
commit
f6006f43a9
37
common/base64.c
Normal file
37
common/base64.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <common/base64.h>
|
||||
#include <sodium.h>
|
||||
#include <sodium/utils.h>
|
||||
|
||||
/* Decode/encode from/to base64, base64 helper functions.
|
||||
* We import base64 from libsodium to generate tor V3 ED25519-V3 onions from blobs
|
||||
*/
|
||||
|
||||
char *b64_encode(const tal_t *ctx, const u8 *data, size_t len)
|
||||
{
|
||||
char *str = tal_arr(ctx, char, sodium_base64_encoded_len(len, sodium_base64_VARIANT_ORIGINAL) + 1);
|
||||
|
||||
str = sodium_bin2base64(str, tal_count(str), data,
|
||||
len, sodium_base64_VARIANT_ORIGINAL);
|
||||
return str;
|
||||
}
|
||||
|
||||
u8 *b64_decode(const tal_t *ctx, const char *str, size_t len)
|
||||
{
|
||||
size_t bin_len = len + 1;
|
||||
|
||||
u8 *ret = tal_arr(ctx, u8, bin_len);
|
||||
|
||||
if (!sodium_base642bin(ret,
|
||||
tal_count(ret),
|
||||
(const char * const)str,
|
||||
len,
|
||||
NULL,
|
||||
&bin_len,
|
||||
NULL,
|
||||
sodium_base64_VARIANT_ORIGINAL))
|
||||
return tal_free(ret);
|
||||
|
||||
ret[bin_len] = 0;
|
||||
tal_resize(&ret, bin_len + 1);
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user