summaryrefslogtreecommitdiff
path: root/inc/polyfill.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2016-05-05 06:45:08 +0200
committerczaks <marcin@6irc.net>2016-05-05 06:45:08 +0200
commitc898f9749367b4ce9eea06ec9dc178baa7752d04 (patch)
tree8eb21f57b88e36c481da8f8a74c32ec52ce4f4ab /inc/polyfill.php
parentc53f13bf90716461780fef0a2b4b6e2b5b3cb002 (diff)
parent7c3126866cd291d515ab5cc83d4635c3c95c6d85 (diff)
Merge branch 'master' of https://github.com/vichan-devel/vichan
Diffstat (limited to 'inc/polyfill.php')
-rw-r--r--inc/polyfill.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/inc/polyfill.php b/inc/polyfill.php
new file mode 100644
index 00000000..ac40a00a
--- /dev/null
+++ b/inc/polyfill.php
@@ -0,0 +1,28 @@
+<?php
+
+// PHP 5.4
+
+if (!function_exists('hex2bin')) {
+ function hex2bin($data) {
+ return pack("H*" , $hex_string);
+ }
+}
+
+// PHP 5.6
+
+if (!function_exists('hash_equals')) {
+ function hash_equals($ours, $theirs) {
+ $ours = (string)$ours;
+ $theirs = (string)$theirs;
+
+ $tlen = strlen($theirs);
+ $olen = strlen($ours);
+
+ $answer = 0;
+ for ($i = 0; $i < $tlen; $i++) {
+ $answer |= ord($ours[$olen > $i ? $i : 0]) ^ ord($theirs[$i]);
+ }
+
+ return $answer === 0 && $olen === $tlen;
+ }
+}