Revert "Refactor Crypto::randomDigits()"

This reverts commit 940884e4bd.
This commit is contained in:
Art4 2025-02-06 08:29:14 +00:00
parent 47db6de393
commit c6ee2c461c
2 changed files with 11 additions and 3 deletions

View file

@ -305,6 +305,13 @@ class Crypto
*/ */
public static function randomDigits($digits) public static function randomDigits($digits)
{ {
return random_int(0, 10 ** $digits - 1); $rn = '';
// generating cryptographically secure pseudo-random integers
for ($i = 0; $i < $digits; $i++) {
$rn .= random_int(0, 9);
}
return (int) $rn;
} }
} }

View file

@ -21,10 +21,11 @@ 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 12345678; return 1;
}); });
self::assertSame(12345678, Crypto::randomDigits(8)); self::assertSame(1, Crypto::randomDigits(1));
self::assertSame(11111111, Crypto::randomDigits(8));
} }
public function testDiasporaPubRsaToMe() public function testDiasporaPubRsaToMe()