php-src/ext/standard/tests/random/random_bytes.phpt
Scott 6554f721f7 Add support for getrandom(2), add type check on file descriptor
Fix to_read, throw exception if syscall fails

Fixes thanks to feedback from sarnold at ##crypto on freenode

Correction on error conditions

Remove dead code (thanks @defuse)

It turns out getrandom can take >256, getentropy refuses.

Better semantics

Thanks @defuse for catching my silly mistake here

Cast to size_t to be explicit

Let's simplify the logic a bit

Let's be consistent; define everything before we do any logic

Continuously check that the file descriptor is still a valid one

Add device type check on fd initialization
2015-09-29 09:14:28 +02:00

17 lines
246 B
PHP

--TEST--
Test normal operation of random_bytes()
--FILE--
<?php
//-=-=-=-
var_dump(strlen(bin2hex(random_bytes(16))));
var_dump(is_string(random_bytes(10)));
var_dump(is_string(random_bytes(257)));
?>
--EXPECT--
int(32)
bool(true)
bool(true)