-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use signed integer instead of unsigned integer for the PRNG's size argument. #40
Conversation
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.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ple13)
src/main/cc/math/open_ssl_uniform_random_generator.h
line 89 at r1 (raw file):
// Generates a vector of pseudorandom bytes with the given size. absl::StatusOr<std::vector<unsigned char>> GeneratePseudorandomBytes( int64_t size) override;
Note that there are other tricks to avoiding implicit conversion1 if we feel like using them. e.g. if we're willing to upgrade to C++20 like we have internally at Google, we can use std::same_as
. Of course this PR is fine as-is assuming we're okay with limiting to sizes that fit into int64_t
and having negative values as a runtime error.
src/test/cc/math/open_ssl_uniform_random_generator_test.cc
line 84 at r1 (raw file):
seq.status(), StatusIs(absl::StatusCode::kInvalidArgument, "Number of pseudorandom bytes must be a non-negative value."));
nit: avoid checking exact error messages. Error messages should not be considered part of the API contract. Use other string matchers such as HasSubstr
with a minimal substring if the message is needed to resolve ambiguities between error conditions.
Suggestion:
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("negative")));
Footnotes
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.
Reviewable status: 3 of 4 files reviewed, all discussions resolved (waiting on @SanjayVas)
src/main/cc/math/open_ssl_uniform_random_generator.h
line 89 at r1 (raw file):
Previously, SanjayVas (Sanjay Vasandani) wrote…
Note that there are other tricks to avoiding implicit conversion1 if we feel like using them. e.g. if we're willing to upgrade to C++20 like we have internally at Google, we can use
std::same_as
. Of course this PR is fine as-is assuming we're okay with limiting to sizes that fit intoint64_t
and having negative values as a runtime error.
Thanks.
src/test/cc/math/open_ssl_uniform_random_generator_test.cc
line 84 at r1 (raw file):
Previously, SanjayVas (Sanjay Vasandani) wrote…
nit: avoid checking exact error messages. Error messages should not be considered part of the API contract. Use other string matchers such as
HasSubstr
with a minimal substring if the message is needed to resolve ambiguities between error conditions.
Done.
Footnotes
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.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @stevenwarejones)
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.
Reviewed 3 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ple13)
The functions GeneratePseudorandomBytes and GenerateUniformRandomRange takes the argument
size
of type uint64_t. This will cause a problem if a negative number is provided. For example, -1 will be implicitly converted to 2^64-1, and GeneratePseudorandomBytes(-1) will become GeneratePseudorandomBytes(2^64-1).