From fbc058cf82381b471183deefd4dc41dc7078cc7e Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 25 Aug 2020 16:18:38 +0200 Subject: [PATCH] add binToHex with Poco::Nullable for easy use with public keys --- src/cpp/lib/DataTypeConverter.cpp | 10 ++++++++++ src/cpp/lib/DataTypeConverter.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cpp/lib/DataTypeConverter.cpp b/src/cpp/lib/DataTypeConverter.cpp index c3275ba49..a97cb8d0e 100644 --- a/src/cpp/lib/DataTypeConverter.cpp +++ b/src/cpp/lib/DataTypeConverter.cpp @@ -176,6 +176,16 @@ namespace DataTypeConverter return hexString; } + std::string binToHex(const Poco::Nullable& nullableBin) + { + if (nullableBin.isNull()) { + return "0x0"; + } + else { + return binToHex(nullableBin.value().content().data(), nullableBin.value().content().size()); + } + } + std::string pubkeyToHex(const unsigned char* pubkey) { auto mm = MemoryManager::getInstance(); diff --git a/src/cpp/lib/DataTypeConverter.h b/src/cpp/lib/DataTypeConverter.h index e1a419a93..46a767d97 100644 --- a/src/cpp/lib/DataTypeConverter.h +++ b/src/cpp/lib/DataTypeConverter.h @@ -5,9 +5,10 @@ #include "../SingletonManager/MemoryManager.h" #include "Poco/Timespan.h" +#include "Poco/Nullable.h" +#include "Poco/Data/LOB.h" #include "../SingletonManager/LanguageManager.h" - namespace DataTypeConverter { enum NumberParseState @@ -26,7 +27,9 @@ namespace DataTypeConverter { std::string binToBase64(const MemoryBin* data); + std::string binToHex(const unsigned char* data, size_t size); + std::string binToHex(const Poco::Nullable& nullableBin); inline std::string binToHex(const MemoryBin* data) { return binToHex(data->data(), data->size());} //! \param pubkey pointer to array with crypto_sign_PUBLICKEYBYTES size