From de5d7aa3317c8547e1ad338613896001fe1aabaf Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 13 Jan 2018 21:39:34 +0100 Subject: [PATCH] Strict ISecure random * Declare strict * Scalar arguments * Return type * Use fully qualified name for strlen Signed-off-by: Roeland Jago Douma --- lib/private/Security/SecureRandom.php | 8 +++++--- lib/public/Security/ISecureRandom.php | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/private/Security/SecureRandom.php b/lib/private/Security/SecureRandom.php index 5bd909ea00..b5270d08b4 100644 --- a/lib/private/Security/SecureRandom.php +++ b/lib/private/Security/SecureRandom.php @@ -21,6 +21,8 @@ * */ +declare(strict_types=1); + namespace OC\Security; use OCP\Security\ISecureRandom; @@ -70,9 +72,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) { diff --git a/lib/public/Security/ISecureRandom.php b/lib/public/Security/ISecureRandom.php index 76e207fbbd..14976831a1 100644 --- a/lib/public/Security/ISecureRandom.php +++ b/lib/public/Security/ISecureRandom.php @@ -23,6 +23,8 @@ * */ +declare(strict_types=1); + namespace OCP\Security; /** @@ -87,7 +89,7 @@ interface ISecureRandom { * @return string * @since 8.0.0 */ - public function generate($length, - $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'); + public function generate(int $length, + string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string; }