-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: Add utilities for generating SHA256 hashes. #491
Conversation
…rom the signer class
commit code review suggestions Co-authored-by: kirkrodrigues <[email protected]>
auto const openssl_err = ERR_get_error(); | ||
return {ERR_error_string(openssl_err, nullptr)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto const openssl_err = ERR_get_error(); | |
return {ERR_error_string(openssl_err, nullptr)}; | |
auto const openssl_err = ERR_get_error(); | |
auto* openssl_err_str = ERR_error_string(openssl_err, nullptr); | |
if (nullptr == openssl_err_str) { | |
return {}; | |
} | |
return {openssl_err_str}; |
Because ERR_error_string
may return nullptr
and std::string{nullptr}
triggers undefined behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. In the nullptr case, should we return some customzied error message so users don't get a "" which could be quite confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, we could. The reason I chose {}
is because if you call this method and no error had occurred, then you would also get nullptr
. So perhaps we should do, in order:
0 == openssl_err
=>{}
nullptr == openssl_err_str
=>{"Unknown error"}
- else =>
{openssl_err_str}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, on no error, ERR_error_string
does return a string. So I guess we can just do the last two bullets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never thought someone will try to call this when there's no error, lol. Sure, sounds fair
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps to be clearer, we can use "Error has no string representation"
instead of "Unknown error"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
"Error has no string representation, error_code: " + std::to_string(openssl_err)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sg
Co-authored-by: kirkrodrigues <[email protected]>
Co-authored-by: kirkrodrigues <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the PR title, how about:
core: Add utilities for generating SHA256 hashes.
|
Sounds good |
Co-authored-by: wraymo <[email protected]> Co-authored-by: Lin Zhihao <[email protected]> Co-authored-by: kirkrodrigues <[email protected]>
Description
The PR introduces a hash_utils.cpp/hpp to generate SHA256 hashes and two simple unit tests.
The PR also remove the CMakefile for Openssl. The file was originally added to fix a bug for Cmake with version < 3.16.0. since the minimum version of CMake we are using is 3.16.2, we can safely remove the file and bumb up the required version of cmake.
Validation performed
Generate a presigned url with s3 https url with the hash utils and confirmed that the presigned url works