Skip to content

Commit

Permalink
Address codeview comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed Jul 30, 2024
1 parent 63f4673 commit 29e6058
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 7 additions & 9 deletions components/core/src/clp/hash_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ class EvpDigestContext {
/**
* Hashes `input` into the digest.
* @param input
* @return ErrorCode_Success on success.
* @return ErrorCode_Failure if `EVP_DigestUpdate` fails.
* @return Whether `EVP_DigestUpdate` succeeded.
*/
[[nodiscard]] auto digest_update(span<unsigned char const> input) -> ErrorCode;
[[nodiscard]] auto digest_update(span<unsigned char const> input) -> bool;

/**
* Writes the digest into `hash` and clears the digest.
Expand All @@ -126,11 +125,11 @@ class EvpDigestContext {
int m_digest_nid{};
};

auto EvpDigestContext::digest_update(span<unsigned char const> input) -> ErrorCode {
auto EvpDigestContext::digest_update(span<unsigned char const> input) -> bool {
if (1 != EVP_DigestUpdate(m_md_ctx, input.data(), input.size())) {
return ErrorCode_Failure;
return false;
}
return ErrorCode_Success;
return true;
}

auto EvpDigestContext::digest_final(vector<unsigned char>& hash) -> ErrorCode {
Expand Down Expand Up @@ -202,10 +201,9 @@ auto get_sha256_hash(span<unsigned char const> input, vector<unsigned char>& has
throw HashUtilsOperationFailed(err.get_error_code(), __FILENAME__, __LINE__, err.what());
}

if (auto const error_code = evp_ctx_manager->digest_update(input);
ErrorCode_Success != error_code)
if (false == evp_ctx_manager->digest_update(input))
{
return error_code;
return ErrorCode_Failure;
}

if (auto const error_code = evp_ctx_manager->digest_final(hash);
Expand Down
5 changes: 3 additions & 2 deletions components/core/src/clp/hash_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HashUtilsOperationFailed : public TraceableException {
* @return ErrorCode_Success on success.
* @return ErrorCode_BadParam if `key` is longer than `INT32_MAX`.
* @return ErrorCode_Failure if hash generation fails.
* @return ErrorCode_Corrupt if `hash` has an unexpected length.
* @return ErrorCode_Corrupt if `hash` has an unexpected length.
*/
[[nodiscard]] auto get_hmac_sha256_hash(
std::span<unsigned char const> input,
Expand All @@ -65,7 +65,8 @@ class HashUtilsOperationFailed : public TraceableException {
* @param input
* @param hash Returns the hash.
* @return ErrorCode_Success on success.
* @return Same as `digest_final` and `digest_update` on failure.
* @return ErrorCode_Failure if digest_update` fails.
* @return Same as `digest_final` if `digest_final` fails.
* @throw HashUtilsOperationFailed if an OpenSSL EVP digest couldn't be created.
*/
[[nodiscard]] auto get_sha256_hash(
Expand Down

0 comments on commit 29e6058

Please sign in to comment.