From 069ec27e6ffe67abc3c3ac68e97d030e5c1fac06 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 2 Jun 2020 15:46:04 +0800 Subject: [PATCH] add type annotation --- app/Services/Cipher/ARGON2I.php | 4 ++-- app/Services/Cipher/BCRYPT.php | 4 ++-- app/Services/Cipher/BaseCipher.php | 19 +++++++++++------ app/Services/Cipher/EncryptInterface.php | 26 ----------------------- app/Services/Cipher/MD5.php | 5 +---- app/Services/Cipher/PHP_PASSWORD_HASH.php | 4 ++-- app/Services/Cipher/SALTED2MD5.php | 5 +---- app/Services/Cipher/SALTED2SHA256.php | 5 +---- app/Services/Cipher/SALTED2SHA512.php | 5 +---- app/Services/Cipher/SHA256.php | 5 +---- app/Services/Cipher/SHA512.php | 5 +---- 11 files changed, 24 insertions(+), 63 deletions(-) delete mode 100644 app/Services/Cipher/EncryptInterface.php diff --git a/app/Services/Cipher/ARGON2I.php b/app/Services/Cipher/ARGON2I.php index 8ed91947..58202d11 100644 --- a/app/Services/Cipher/ARGON2I.php +++ b/app/Services/Cipher/ARGON2I.php @@ -4,12 +4,12 @@ namespace App\Services\Cipher; class ARGON2I extends BaseCipher { - public function hash($value, $salt = '') + public function hash($value, $salt = ''): string { return password_hash($value, PASSWORD_ARGON2I); } - public function verify($password, $hash, $salt = '') + public function verify($password, $hash, $salt = ''): bool { return password_verify($password, $hash); } diff --git a/app/Services/Cipher/BCRYPT.php b/app/Services/Cipher/BCRYPT.php index 7f9ec885..a2903698 100644 --- a/app/Services/Cipher/BCRYPT.php +++ b/app/Services/Cipher/BCRYPT.php @@ -4,12 +4,12 @@ namespace App\Services\Cipher; class BCRYPT extends BaseCipher { - public function hash($value, $salt = '') + public function hash($value, $salt = ''): string { return password_hash($value, PASSWORD_BCRYPT); } - public function verify($password, $hash, $salt = '') + public function verify($password, $hash, $salt = ''): bool { return password_verify($password, $hash); } diff --git a/app/Services/Cipher/BaseCipher.php b/app/Services/Cipher/BaseCipher.php index c2dedbbf..7c227709 100644 --- a/app/Services/Cipher/BaseCipher.php +++ b/app/Services/Cipher/BaseCipher.php @@ -2,19 +2,24 @@ namespace App\Services\Cipher; -abstract class BaseCipher implements EncryptInterface +abstract class BaseCipher { /** - * {@inheritdoc} + * Encrypt given string with given salt. + * + * @param string $value + * @param string $salt */ - public function hash($value, $salt = '') - { - } + public abstract function hash($value, $salt = ''); /** - * {@inheritdoc} + * Verify that the given hash matches the given password. + * + * @param string $password + * @param string $hash + * @param string $salt */ - public function verify($password, $hash, $salt = '') + public function verify($password, $hash, $salt = '') { return hash_equals($hash, $this->hash($password, $salt)); } diff --git a/app/Services/Cipher/EncryptInterface.php b/app/Services/Cipher/EncryptInterface.php deleted file mode 100644 index 32d30763..00000000 --- a/app/Services/Cipher/EncryptInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -