Skip to content

Commit

Permalink
Added hash_equals for PHP 5.4 and PHP 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipEverything committed Aug 2, 2018
1 parent 277ba44 commit 338497f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/Type/Encrypted.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,21 @@ private function aes256_decrypt($key, $hashing, $cipher, $data)
}
}
}

/*
* Added hash_equals to support PHP 5.4 and PHP 5.5
* hash_equals is built-in from PHP 5.6
* Source: http://php.net/manual/en/function.hash-equals.php
*/
if(!function_exists('hash_equals')) {
function hash_equals($str1, $str2) {
if(strlen($str1) != strlen($str2)) {
return false;
} else {
$res = $str1 ^ $str2;
$ret = 0;
for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]);
return !$ret;
}
}
}

0 comments on commit 338497f

Please sign in to comment.