Merge pull request #7849 from nextcloud/strict_securerandom
Strict ISecure random
This commit is contained in:
commit
fcea6e1564
|
@ -55,9 +55,9 @@ class TokenHandlerTest extends \Test\TestCase {
|
|||
$this->expectedTokenLength,
|
||||
ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturn('mytoken');
|
||||
|
||||
$this->assertTrue($this->tokenHandler->generateToken());
|
||||
$this->assertSame('mytoken', $this->tokenHandler->generateToken());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -70,9 +71,9 @@ class SecureRandom implements ISecureRandom {
|
|||
* specified all valid base64 characters are used.
|
||||
* @return string
|
||||
*/
|
||||
public function generate($length,
|
||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') {
|
||||
$maxCharIndex = strlen($characters) - 1;
|
||||
public function generate(int $length,
|
||||
string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string {
|
||||
$maxCharIndex = \strlen($characters) - 1;
|
||||
$randomString = '';
|
||||
|
||||
while($length > 0) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -87,7 +88,7 @@ interface ISecureRandom {
|
|||
* @return string
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function generate($length,
|
||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
|
||||
public function generate(int $length,
|
||||
string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue