X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fparagonie%2Frandom_compat%2Flib%2Frandom_bytes_dev_urandom.php;h=5e0ac0e3e3999f038f46bfdd27add5df9bd15fda;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hp=df5b91524e893831af5598318e89cd8ee0c5876f;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php b/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php index df5b91524..5e0ac0e3e 100644 --- a/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php +++ b/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php @@ -5,7 +5,7 @@ * * 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 @@ -46,7 +46,9 @@ if (!is_callable('random_bytes')) { */ function random_bytes($bytes) { + /** @var resource $fp */ static $fp = null; + /** * This block should only be run once */ @@ -55,8 +57,10 @@ if (!is_callable('random_bytes')) { * 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 $st */ $st = fstat($fp); if (($st['mode'] & 0170000) !== 020000) { fclose($fp); @@ -64,7 +68,7 @@ if (!is_callable('random_bytes')) { } } - if (!empty($fp)) { + if (is_resource($fp)) { /** * stream_set_read_buffer() does not exist in HHVM * @@ -83,6 +87,7 @@ if (!is_callable('random_bytes')) { } try { + /** @var int $bytes */ $bytes = RandomCompat_intval($bytes); } catch (TypeError $ex) { throw new TypeError( @@ -103,7 +108,7 @@ if (!is_callable('random_bytes')) { * if (empty($fp)) line is logic that should only be run once per * page load. */ - if (!empty($fp)) { + if (is_resource($fp)) { /** * @var int */