Skip to content

Commit

Permalink
Merge pull request #290 from sarciszewski/patch-1
Browse files Browse the repository at this point in the history
Remove side-effects in hash_equals()
  • Loading branch information
alexbilbie committed Jan 1, 2015
2 parents 740ea24 + 6127754 commit 19b64c2
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/TokenType/MAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,18 @@ public function determineAccessTokenInHeader(Request $request)
*/
private function hash_equals($knownString, $userString)
{
if (!function_exists('hash_equals')) {
function hash_equals($knownString, $userString)
{
if (strlen($knownString) !== strlen($userString)) {
return false;
}
$len = strlen($knownString);
$result = 0;
for ($i = 0; $i < $len; $i++) {
$result |= (ord($knownString[$i]) ^ ord($userString[$i]));
}
// They are only identical strings if $result is exactly 0...
return 0 === $result;
}
if (function_exists('\hash_equals')) {
return \hash_equals($knownString, $userString);
}

return hash_equals($knownString, $userString);
if (strlen($knownString) !== strlen($userString)) {
return false;
}
$len = strlen($knownString);
$result = 0;
for ($i = 0; $i < $len; $i++) {
$result |= (ord($knownString[$i]) ^ ord($userString[$i]));
}
// They are only identical strings if $result is exactly 0...
return 0 === $result;
}
}

0 comments on commit 19b64c2

Please sign in to comment.