summaryrefslogtreecommitdiffstats
path: root/lib/private/Security/Hasher.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-16 20:28:22 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-01-16 22:01:19 +0100
commit0e0db3765887930682aadc6bc8ec7df5ffd187f6 (patch)
treef11f9ebd73638273d281cb6d635ba6069edefd9f /lib/private/Security/Hasher.php
parent2b70c708abc667c3e3c4fd9a97626012bf1ded25 (diff)
downloadnextcloud-server-0e0db3765887930682aadc6bc8ec7df5ffd187f6.tar.gz
nextcloud-server-0e0db3765887930682aadc6bc8ec7df5ffd187f6.zip
Make OCP\Security stricter
* Add typehints * Add return types * Opcode opts from phpstorm * Made strict * Fixed tests: No need to test bogus values anymore strict typing fixes this Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Security/Hasher.php')
-rw-r--r--lib/private/Security/Hasher.php17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php
index 1ba6d7059eb..c6c9109b336 100644
--- a/lib/private/Security/Hasher.php
+++ b/lib/private/Security/Hasher.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -63,7 +64,7 @@ class Hasher implements IHasher {
$this->config = $config;
$hashingCost = $this->config->getSystemValue('hashingCost', null);
- if(!is_null($hashingCost)) {
+ if(!\is_null($hashingCost)) {
$this->options['cost'] = $hashingCost;
}
}
@@ -76,7 +77,7 @@ class Hasher implements IHasher {
* @param string $message Message to generate hash from
* @return string Hash of the message with appended version parameter
*/
- public function hash($message) {
+ public function hash(string $message): string {
return $this->currentVersion . '|' . password_hash($message, PASSWORD_DEFAULT, $this->options);
}
@@ -85,9 +86,9 @@ class Hasher implements IHasher {
* @param string $prefixedHash
* @return null|array Null if the hash is not prefixed, otherwise array('version' => 1, 'hash' => 'foo')
*/
- protected function splitHash($prefixedHash) {
+ protected function splitHash(string $prefixedHash) {
$explodedString = explode('|', $prefixedHash, 2);
- if(count($explodedString) === 2) {
+ if(\count($explodedString) === 2) {
if((int)$explodedString[0] > 0) {
return array('version' => (int)$explodedString[0], 'hash' => $explodedString[1]);
}
@@ -103,13 +104,13 @@ class Hasher implements IHasher {
* @param null|string &$newHash Reference will contain the updated hash
* @return bool Whether $hash is a valid hash of $message
*/
- protected function legacyHashVerify($message, $hash, &$newHash = null) {
+ protected function legacyHashVerify($message, $hash, &$newHash = null): bool {
if(empty($this->legacySalt)) {
$this->legacySalt = $this->config->getSystemValue('passwordsalt', '');
}
// Verify whether it matches a legacy PHPass or SHA1 string
- $hashLength = strlen($hash);
+ $hashLength = \strlen($hash);
if($hashLength === 60 && password_verify($message.$this->legacySalt, $hash) ||
$hashLength === 40 && hash_equals($hash, sha1($message))) {
$newHash = $this->hash($message);
@@ -126,7 +127,7 @@ class Hasher implements IHasher {
* @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
* @return bool Whether $hash is a valid hash of $message
*/
- protected function verifyHashV1($message, $hash, &$newHash = null) {
+ protected function verifyHashV1(string $message, string $hash, &$newHash = null): bool {
if(password_verify($message, $hash)) {
if(password_needs_rehash($hash, PASSWORD_DEFAULT, $this->options)) {
$newHash = $this->hash($message);
@@ -143,7 +144,7 @@ class Hasher implements IHasher {
* @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
* @return bool Whether $hash is a valid hash of $message
*/
- public function verify($message, $hash, &$newHash = null) {
+ public function verify(string $message, string $hash, &$newHash = null): bool {
$splittedHash = $this->splitHash($hash);
if(isset($splittedHash['version'])) {