Repository navigation
Conversation
First attempt at random_int(). Commented-out random_hex() until the other functions are rocking.
Changes from my fork of rand-bytes
There was a problem hiding this comment.
Probably that should be RETURN_FALSE as well? Same in random_int.
There was a problem hiding this comment.
Nice catch! I'll fix.
There was a problem hiding this comment.
since you already have LONG_MIN and LONG_MAX, so if only minimum value min is given. then simply assume it means min to LONG_MAX?
There was a problem hiding this comment.
@laruence: I thought about the same thing but then I realize that reading:
random_int(10);
might be understood as 10 being the max.
There was a problem hiding this comment.
hmm, that could be a doc issue.. but it's not a big deal :)
There was a problem hiding this comment.
Oops - this is a dingleberry left over from when min and max were optional args. They are both required in the current spec that's being voted on. I'll remove this check. :)
There was a problem hiding this comment.
We need to make sure the min & max values weren't the same.
There was a problem hiding this comment.
You're already checking this on line 126.
There was a problem hiding this comment.
Oh snap. Not. Enough. Coffee! Oh wait, I'm drinking decaf for some reason today. :/
|
Congratulations on passing unanimously! One thing: Will you ever support the (I didn't see anything in the RFC and I'm not really awake enough to peruse the code.) |
|
@sarciszewski This is something we have discussed, but decided to leave for future scope. If you compile against LibreSSL and have a Linux Kernel version > 3.17, you will be using |
|
The vote passed, but was never closed. This should be merged soon ;-) |
There was a problem hiding this comment.
This needs to be moved into the while look (combined declaration and assignment) to conform with C89.
|
Thanks for the push @ircmaxell! :) I'm coordinating with @lt to get this bad boy ready for merge. :) |
There was a problem hiding this comment.
@SammyK Since both parameters are required, we don't need these defaults any more.
|
Hokay! @lt updated this PR based on feedback. I normalized the return values when errors happen & updated the tests & merged in the lest from master & fixed conflicts. Phew! The RFC officially passed unanimously and this PR can be merged into master now. W00t! Not sure if @nikic is the one to do that or who we need to ping. Thanks again @ircmaxell, @lt, @rdlowrey, and all the other kids who help me along on this one! 🐻 Let's do some more of these! :D |
|
Merged via #1268. Thanks everyone who worked on this! |
|
Yay! Thanks @nikic! :) |
|
Good point. I think a |
|
@lt: I just pushed up a branch with this change, can you take a look? :) |
|
@SammyK What should happen if |
|
I think when we wrote this, exceptions in the engine hadn't yet passed. I'd be happy with InvalidArgumentException for |
|
Should |
|
When someone tries to generate an empty string using the CSPRNG, I think it's likely a programming error (if it were my project, I'd define it as a programming error). So I think it is safer if PHP treats this case as invalid. And, from the other point of view, I think PHP can reasonably reject bug reports that you can't generate empty strings with the CSPRNG, especially if the conditions for these exceptions are documented. |
|
If it's not a programming error, it's a stupid thing to do. Invalid all the way. |
|
At least |
|
@CodesInChaos I agree. |
|
I'll disagree with practically useful. But I'll agree that it should be allowed, in the "spirit of PHP" If we're going to allow if (min >= max) {
if (min == max) {
RETURN_LONG(min);
}
zend_throw_exception(spl_ce_InvalidArgumentException, "Maximum value must not be less than the minimum value", 0);
return;
}@SammyK perhaps do something like this for SPL exceptions: Line 606 in ed1b648 |
|
Please do the change to exceptions separately from the changing any error conditions. |
|
Sounds good. I'll submit 2 separate PR's - one for throwing general exceptions and one for new error conditions. Then I'll update the docs when they are merged and post here for another once-over to make sure the docs cover all the bases. :) |
Submitting as a PR per @nikic's recommendation.
RFC can be found here.