Add dumpBuffer() in libgourou_common

This commit is contained in:
Grégory Soutadé 2022-08-27 15:42:11 +02:00
parent 7084fb7025
commit 56b3231f92
3 changed files with 17 additions and 24 deletions

View File

@ -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; i<len; i++)
{
if (i && !(i%16)) printf("\n");
printf("%02x ", data[i]);
}
printf("\n");
}
}
#endif

View File

@ -226,14 +226,7 @@ namespace gourou
client->digestFinalize(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);

View File

@ -46,7 +46,6 @@
#include <zip.h>
#include <libgourou_common.h>
#include <libgourou_log.h>
#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,