mirror of
https://github.com/friendica/friendica
synced 2024-11-15 01:42:53 +00:00
Refactor Crypto::randomDigits()
This commit is contained in:
parent
29c0473b64
commit
940884e4bd
2 changed files with 3 additions and 11 deletions
|
@ -306,13 +306,6 @@ class Crypto
|
||||||
*/
|
*/
|
||||||
public static function randomDigits($digits)
|
public static function randomDigits($digits)
|
||||||
{
|
{
|
||||||
$rn = '';
|
return random_int(0, 10 ** $digits - 1);
|
||||||
|
|
||||||
// generating cryptographically secure pseudo-random integers
|
|
||||||
for ($i = 0; $i < $digits; $i++) {
|
|
||||||
$rn .= random_int(0, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int) $rn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,10 @@ class CryptoTest extends TestCase
|
||||||
{
|
{
|
||||||
$random_int = $this->getFunctionMock('Friendica\Util', 'random_int');
|
$random_int = $this->getFunctionMock('Friendica\Util', 'random_int');
|
||||||
$random_int->expects($this->any())->willReturnCallback(function($min, $max) {
|
$random_int->expects($this->any())->willReturnCallback(function($min, $max) {
|
||||||
return 1;
|
return 12345678;
|
||||||
});
|
});
|
||||||
|
|
||||||
self::assertSame(1, Crypto::randomDigits(1));
|
self::assertSame(12345678, Crypto::randomDigits(8));
|
||||||
self::assertSame(11111111, Crypto::randomDigits(8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataRsa(): array
|
public function dataRsa(): array
|
||||||
|
|
Loading…
Reference in a new issue