szaszm commented on code in PR #1583: URL: https://github.com/apache/nifi-minifi-cpp/pull/1583#discussion_r1246256189
########## extensions/standard-processors/processors/HashContent.h: ########## @@ -49,21 +48,25 @@ namespace { // NOLINT HashReturnType ret_val; ret_val.second = 0; std::array<std::byte, HASH_BUFFER_SIZE> buffer{}; - MD5_CTX context; - MD5_Init(&context); + EVP_MD_CTX *context = EVP_MD_CTX_new(); + const auto guard = gsl::finally([&context]() { + EVP_MD_CTX_free(context); + }); + const EVP_MD *md = EVP_md5(); + EVP_DigestInit_ex(context, md, nullptr); Review Comment: Is there any reason not to inline the digest type call? ```suggestion EVP_DigestInit_ex(context, EVP_md5(), nullptr); ``` ########## libminifi/src/core/state/Value.cpp: ########## @@ -34,25 +34,29 @@ const std::type_index Value::BOOL_TYPE = std::type_index(typeid(bool)); const std::type_index Value::DOUBLE_TYPE = std::type_index(typeid(double)); const std::type_index Value::STRING_TYPE = std::type_index(typeid(std::string)); -void hashNode(const SerializedResponseNode& node, SHA512_CTX& ctx) { - SHA512_Update(&ctx, node.name.c_str(), node.name.length()); +void hashNode(const SerializedResponseNode& node, EVP_MD_CTX* ctx) { Review Comment: If ctx is expected to be valid/not-null, then keeping it as a reference would document this on the interface. ########## extensions/standard-processors/processors/HashContent.h: ########## @@ -49,21 +48,25 @@ namespace { // NOLINT HashReturnType ret_val; ret_val.second = 0; std::array<std::byte, HASH_BUFFER_SIZE> buffer{}; - MD5_CTX context; - MD5_Init(&context); + EVP_MD_CTX *context = EVP_MD_CTX_new(); + const auto guard = gsl::finally([&context]() { + EVP_MD_CTX_free(context); + }); + const EVP_MD *md = EVP_md5(); + EVP_DigestInit_ex(context, md, nullptr); size_t ret = 0; do { ret = stream->read(buffer); if (ret > 0) { - MD5_Update(&context, buffer.data(), ret); + EVP_DigestUpdate(context, buffer.data(), ret); ret_val.second += gsl::narrow<int64_t>(ret); } } while (ret > 0); if (ret_val.second > 0) { - std::array<std::byte, MD5_DIGEST_LENGTH> digest{}; - MD5_Final(reinterpret_cast<unsigned char*>(digest.data()), &context); + std::array<std::byte, EVP_MAX_MD_SIZE> digest{}; + EVP_DigestFinal_ex(context, reinterpret_cast<unsigned char*>(digest.data()), nullptr); Review Comment: The array is sized for SHA512 now. Did you verify that the resulting hash is trimmed to MD5 size? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org