*
* The MIT License (MIT)
*
- * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
+ * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
*/
function random_bytes($bytes)
{
+ /** @var resource $fp */
static $fp = null;
+
/**
* This block should only be run once
*/
* We use /dev/urandom if it is a char device.
* We never fall back to /dev/random
*/
+ /** @var resource|bool $fp */
$fp = fopen('/dev/urandom', 'rb');
- if (!empty($fp)) {
+ if (is_resource($fp)) {
+ /** @var array<string, int> $st */
$st = fstat($fp);
if (($st['mode'] & 0170000) !== 020000) {
fclose($fp);
}
}
- if (!empty($fp)) {
+ if (is_resource($fp)) {
/**
* stream_set_read_buffer() does not exist in HHVM
*
}
try {
+ /** @var int $bytes */
$bytes = RandomCompat_intval($bytes);
} catch (TypeError $ex) {
throw new TypeError(
* if (empty($fp)) line is logic that should only be run once per
* page load.
*/
- if (!empty($fp)) {
+ if (is_resource($fp)) {
/**
* @var int
*/