* Fix PHP7.2 issue with HashRNGProvider

* Fix PHP7.1+ issue with MCryptRNGProvider
This commit is contained in:
RobThree
2018-06-06 01:47:03 +02:00
parent fac4ebd44b
commit 0ac68f6b86
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ class HashRNGProvider implements IRNGProvider
$hash = mt_rand();
for ($i = 0; $i < $bytecount; $i++) {
$hash = hash($this->algorithm, $hash.mt_rand(), true);
$result .= $hash[mt_rand(0, sizeof($hash))];
$result .= $hash[mt_rand(0, strlen($hash)-1)];
}
return $result;
}
+6 -4
View File
@@ -317,10 +317,12 @@ class TwoFactorAuthTest extends PHPUnit_Framework_TestCase
* @requires function mcrypt_create_iv
*/
public function testMCryptRNGProvidersReturnExpectedNumberOfBytes() {
$rng = new \RobThree\Auth\Providers\Rng\MCryptRNGProvider();
foreach ($this->getRngTestLengths() as $l)
$this->assertEquals($l, strlen($rng->getRandomBytes($l)));
$this->assertEquals(true, $rng->isCryptographicallySecure());
if (function_exists('mcrypt_create_iv')) {
$rng = new \RobThree\Auth\Providers\Rng\MCryptRNGProvider();
foreach ($this->getRngTestLengths() as $l)
$this->assertEquals($l, strlen($rng->getRandomBytes($l)));
$this->assertEquals(true, $rng->isCryptographicallySecure());
}
}
/**