Strict ISecure random

* Declare strict
* Scalar arguments
* Return type
* Use fully qualified name for strlen

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-01-13 21:39:34 +01:00
parent 60f38d37fe
commit de5d7aa331
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 9 additions and 5 deletions

View File

@ -21,6 +21,8 @@
* *
*/ */
declare(strict_types=1);
namespace OC\Security; namespace OC\Security;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
@ -70,9 +72,9 @@ class SecureRandom implements ISecureRandom {
* specified all valid base64 characters are used. * specified all valid base64 characters are used.
* @return string * @return string
*/ */
public function generate($length, public function generate(int $length,
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') { string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string {
$maxCharIndex = strlen($characters) - 1; $maxCharIndex = \strlen($characters) - 1;
$randomString = ''; $randomString = '';
while($length > 0) { while($length > 0) {

View File

@ -23,6 +23,8 @@
* *
*/ */
declare(strict_types=1);
namespace OCP\Security; namespace OCP\Security;
/** /**
@ -87,7 +89,7 @@ interface ISecureRandom {
* @return string * @return string
* @since 8.0.0 * @since 8.0.0
*/ */
public function generate($length, public function generate(int $length,
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'); string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string;
} }