From 56b3231f92e327d841d5775ebcf9cd757e630c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 27 Aug 2022 15:42:11 +0200 Subject: [PATCH] Add dumpBuffer() in libgourou_common --- include/libgourou_common.h | 14 ++++++++++++++ src/libgourou.cpp | 18 +++--------------- utils/drmprocessorclientimpl.cpp | 9 --------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/libgourou_common.h b/include/libgourou_common.h index f8ab290..bd4117b 100644 --- a/include/libgourou_common.h +++ b/include/libgourou_common.h @@ -415,6 +415,20 @@ namespace gourou } return 0; } + + static inline void dumpBuffer(GOUROU_LOG_LEVEL level, const char* title, const unsigned char* data, unsigned int len) + { + if (gourou::logLevel < level) + return; + + printf("%s", title); + for(unsigned int i=0; idigestFinalize(sha_ctx, sha_out); - if (logLevel >= LG_LOG_DEBUG) - { - printf("\nSHA OUT : "); - for(int i=0; i<(int)SHA1_LEN; i++) - printf("%02x ", sha_out[i]); - printf("\n"); - - } + dumpBuffer(gourou::LG_LOG_DEBUG, "\nSHA OUT : ", sha_out, SHA1_LEN); } void DRMProcessor::signNode(pugi::xml_node& rootNode) @@ -252,13 +245,8 @@ namespace gourou client->RSAPrivateEncrypt(privateRSAKey.data(), privateRSAKey.length(), RSAInterface::RSA_KEY_PKCS12, deviceKey.toBase64().data(), sha_out, sizeof(sha_out), res); - if (logLevel >= LG_LOG_DEBUG) - { - printf("Sig : "); - for(int i=0; i<(int)sizeof(res); i++) - printf("%02x ", res[i]); - printf("\n"); - } + + dumpBuffer(gourou::LG_LOG_DEBUG, "Sig : ", res, sizeof(res)); std::string signature = ByteArray(res, sizeof(res)).toBase64(); appendTextElem(rootNode, "adept:signature", signature); diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index c62e2d8..9f17171 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -46,7 +46,6 @@ #include #include -#include #include "drmprocessorclientimpl.h" DRMProcessorClientImpl::DRMProcessorClientImpl(): @@ -403,14 +402,6 @@ void DRMProcessorClientImpl::RSAPrivateDecrypt(const unsigned char* RSAKey, unsi if (ret <= 0) EXCEPTION(gourou::CLIENT_RSA_ERROR, ERR_error_string(ERR_get_error(), NULL)); - - if (gourou::logLevel >= gourou::LG_LOG_DEBUG) - { - printf("Decrypted : "); - for(int i=0; i<(int)outlen; i++) - printf("%02x ", res[i]); - printf("\n"); - } } void DRMProcessorClientImpl::RSAPublicEncrypt(const unsigned char* RSAKey, unsigned int RSAKeyLength,