From 1c70b0f42f1ce95ffcfc6e7d669f415a91845fb7 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 21 Sep 2021 16:04:05 -0400 Subject: [PATCH] add lokinet_hex_to_base32z --- include/lokinet/lokinet_misc.h | 5 +++++ llarp/lokinet_shared.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/lokinet/lokinet_misc.h b/include/lokinet/lokinet_misc.h index dea41f9ba..fa20911e4 100644 --- a/include/lokinet/lokinet_misc.h +++ b/include/lokinet/lokinet_misc.h @@ -21,6 +21,11 @@ extern "C" int EXPORT lokinet_log_level(const char*); + /// @brief take in hex and turn it into base32z + /// @return value must be free()'d later + char* EXPORT + lokinet_hex_to_base32z(const char* hex); + #ifdef __cplusplus } #endif diff --git a/llarp/lokinet_shared.cpp b/llarp/lokinet_shared.cpp index 0766be0f4..3020889e2 100644 --- a/llarp/lokinet_shared.cpp +++ b/llarp/lokinet_shared.cpp @@ -12,6 +12,8 @@ #include +#include + #include #ifdef _WIN32 @@ -546,6 +548,13 @@ extern "C" return id; } + char* EXPORT + lokinet_hex_to_base32z(const char* hex) + { + const auto base32z = oxenmq::to_base32z(oxenmq::from_hex(std::string{hex})); + return strdup(base32z.c_str()); + } + void EXPORT lokinet_close_stream(int stream_id, struct lokinet_context* ctx) {