Merge pull request #7849 from nextcloud/strict_securerandom

Strict ISecure random
This commit is contained in:
Morris Jobke 2018-01-14 21:05:19 +01:00 committed by GitHub
commit fcea6e1564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View File

@ -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());
}

View File

@ -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) {

View File

@ -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;
}