From 9556fe862fd461451ad7bd5e5dc1753db0c0bb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 3 Apr 2022 09:28:19 +0200 Subject: [PATCH] Optimization : Add signature node into signNode() instead of returing it and be added after --- include/libgourou.h | 2 +- src/libgourou.cpp | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/libgourou.h b/include/libgourou.h index abf72d5..88d8c63 100644 --- a/include/libgourou.h +++ b/include/libgourou.h @@ -210,7 +210,7 @@ namespace gourou void pushTag(void* sha_ctx, uint8_t tag); void hashNode(const pugi::xml_node& root, void *sha_ctx, std::map nsHash); void hashNode(const pugi::xml_node& root, unsigned char* sha_out); - std::string signNode(const pugi::xml_node& rootNode); + void signNode(pugi::xml_node& rootNode); void addNonce(pugi::xml_node& root); void buildAuthRequest(pugi::xml_document& authReq); void buildInitLicenseServiceRequest(pugi::xml_document& initLicReq, std::string operatorURL); diff --git a/src/libgourou.cpp b/src/libgourou.cpp index 6ec3e07..b77bea8 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -236,7 +236,7 @@ namespace gourou } } - std::string DRMProcessor::signNode(const pugi::xml_node& rootNode) + void DRMProcessor::signNode(pugi::xml_node& rootNode) { // Compute hash unsigned char sha_out[SHA1_LEN]; @@ -260,9 +260,8 @@ namespace gourou printf("\n"); } - ByteArray signature(res, sizeof(res)); - - return signature.toBase64(); + std::string signature = ByteArray(res, sizeof(res)).toBase64(); + appendTextElem(rootNode, "adept:signature", signature); } void DRMProcessor::addNonce(pugi::xml_node& root) @@ -368,8 +367,7 @@ namespace gourou addNonce(root); appendTextElem(root, "adept:user", user->getUUID()); - std::string signature = signNode(root); - appendTextElem(root, "adept:signature", signature); + signNode(root); } void DRMProcessor::doOperatorAuth(std::string operatorURL) @@ -530,12 +528,10 @@ namespace gourou hmacParentNode.remove_child(hmacNode); - std::string signature = signNode(rootNode); + signNode(rootNode); // Add removed HMAC appendTextElem(hmacParentNode, hmacNode.name(), hmacNode.first_child().value()); - - appendTextElem(rootNode, "adept:signature", signature); pugi::xpath_node node = acsmDoc.select_node("//operatorURL"); if (!node) @@ -823,10 +819,7 @@ namespace gourou pugi::xml_node root = activateReq.select_node("adept:activate").node(); - std::string signature = signNode(root); - - root = activateReq.select_node("adept:activate").node(); - appendTextElem(root, "adept:signature", signature); + signNode(root); pugi::xml_document activationDoc; user->readActivation(activationDoc);