]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add custom hex2bin implementation for 5.3
authorLukas Reschke <lukas@owncloud.com>
Thu, 11 Sep 2014 07:51:45 +0000 (09:51 +0200)
committerLukas Reschke <lukas@owncloud.com>
Thu, 11 Sep 2014 07:51:45 +0000 (09:51 +0200)
Fixes https://github.com/owncloud/core/issues/11004

lib/private/security/crypto.php

index 6fdff8d92a282c9d730424c7ebe175936a0c6862..498e15d6bc3577651414eecd4953797b944d3061 100644 (file)
@@ -42,6 +42,22 @@ class Crypto implements ICrypto {
                $this->random = $random;
        }
 
+       /**
+        * Custom implementation of hex2bin since the function is only available starting
+        * with PHP 5.4
+        *
+        * @TODO Remove this once 5.3 support for ownCloud is dropped
+        * @param $message
+        * @return string
+        */
+       protected static function hexToBin($message) {
+               if (function_exists('hex2bin')) {
+                       return hex2bin($message);
+               }
+
+               return pack("H*", $message);
+       }
+
        /**
         * @param string $message The message to authenticate
         * @param string $password Password to use (defaults to `secret` in config.php)
@@ -99,9 +115,9 @@ class Crypto implements ICrypto {
                        throw new \Exception('Authenticated ciphertext could not be decoded.');
                }
 
-               $ciphertext = hex2bin($parts[0]);
+               $ciphertext = self::hexToBin($parts[0]);
                $iv = $parts[1];
-               $hmac = hex2bin($parts[2]);
+               $hmac = self::hexToBin($parts[2]);
 
                $this->cipher->setIV($iv);