From 5060fd97f0f69ae1f55214cfae34839918924f42 Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 5 Jun 2020 13:26:06 +0200 Subject: [PATCH] add specific pubkey to hex converter for used with new key pair classes --- src/cpp/lib/BinHexConverter.cpp | 18 ++++++++++++++++++ src/cpp/lib/BinHexConverter.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/cpp/lib/BinHexConverter.cpp b/src/cpp/lib/BinHexConverter.cpp index 8f8f78535..cf6608d71 100644 --- a/src/cpp/lib/BinHexConverter.cpp +++ b/src/cpp/lib/BinHexConverter.cpp @@ -109,6 +109,24 @@ std::string convertBinToHex(const MemoryBin* data) sodium_bin2hex(*hex, hexSize, *data, binSize); + std::string hexString((const char*)*hex, hexSize); + mm->releaseMemory(hex); + return hexString; +} + +std::string convertPubkeyToHex(const unsigned char* pubkey) +{ + auto mm = MemoryManager::getInstance(); + size_t hexSize = crypto_sign_PUBLICKEYBYTES * 2 + 1; + size_t binSize = crypto_sign_PUBLICKEYBYTES; + + MemoryBin* hex = mm->getFreeMemory(hexSize); + memset(*hex, 0, hexSize); + + size_t resultBinSize = 0; + + sodium_bin2hex(*hex, hexSize, pubkey, binSize); + std::string hexString((const char*)*hex, hexSize); mm->releaseMemory(hex); return hexString; diff --git a/src/cpp/lib/BinHexConverter.h b/src/cpp/lib/BinHexConverter.h index 563f73ea6..7645f16d7 100644 --- a/src/cpp/lib/BinHexConverter.h +++ b/src/cpp/lib/BinHexConverter.h @@ -9,6 +9,8 @@ MemoryBin* convertBase64ToBin(const std::string& base64String); std::string convertBinToBase64(const MemoryBin* data); std::string convertBinToHex(const MemoryBin* data); +//! \param pubkey pointer to array with crypto_sign_PUBLICKEYBYTES size +std::string convertPubkeyToHex(const unsigned char* pubkey);