Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP8 errors and deprecation warnings #6

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions Auth/SASL/SCRAM.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@

class Auth_SASL_SCRAM extends Auth_SASL_Common
{
private $hash;
private $hmac;
private $gs2_header;
private $cnonce;
private $first_message_bare;
private $saltedPassword;
private $authMessage;

/**
* Construct a SCRAM-H client where 'H' is a cryptographic hash function.
*
Expand Down Expand Up @@ -79,21 +87,33 @@ function __construct($hash)
'sha512' => 'sha512');
if (function_exists('hash_hmac') && isset($hashes[$hash]))
{
$this->hash = create_function('$data', 'return hash("' . $hashes[$hash] . '", $data, TRUE);');
$this->hmac = create_function('$key,$str,$raw', 'return hash_hmac("' . $hashes[$hash] . '", $str, $key, $raw);');
$selectedHash = $hashes[$hash];
$this->hash = function($data) use ($selectedHash) {
return hash($selectedHash, $data, TRUE);
};
$this->hmac = function($key,$str,$raw) use ($selectedHash) {
return hash_hmac($selectedHash, $str, $key, $raw);
};
}
elseif ($hash == 'md5')
{
$this->hash = create_function('$data', 'return md5($data, true);');
$this->hash = function($data) {
return md5($data, true);
};
$this->hmac = array($this, '_HMAC_MD5');
}
elseif (in_array($hash, array('sha1', 'sha-1')))
{
$this->hash = create_function('$data', 'return sha1($data, true);');
$this->hash = function($data) {
return sha1($data, true);
};
$this->hmac = array($this, '_HMAC_SHA1');
}
else
else {
return PEAR::raiseError('Invalid SASL mechanism type');
}

return true;
}

/**
Expand Down Expand Up @@ -256,7 +276,7 @@ public function processOutcome($data)
* Hi() call, which is essentially PBKDF2 (RFC-2898) with HMAC-H() as the pseudorandom function.
*
* @param string $str The string to hash.
* @param string $hash The hash value.
* @param string $salt The salt value.
* @param int $i The iteration count.
* @access private
*/
Expand Down