From 65a26d707abeb2eafc23d3ecd1fad159a47fbec7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 20 Jun 2016 11:04:19 +0200 Subject: [PATCH] keep Travis happy by only conditional defining hash_pbkdf2 in polyfill --- api/src/Mail/hash_pbkdf2.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/api/src/Mail/hash_pbkdf2.php b/api/src/Mail/hash_pbkdf2.php index fe3650091a..78a1d53072 100644 --- a/api/src/Mail/hash_pbkdf2.php +++ b/api/src/Mail/hash_pbkdf2.php @@ -5,21 +5,25 @@ * @author Sebastiaan Stok * @link https://github.com/symfony/polyfill-php55/blob/master/Php55.php */ -function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) + +if (!function_exists('hash_pbkdf2')) { - // Number of blocks needed to create the derived key - $blocks = ceil($length / strlen(hash($algorithm, null, true))); - $digest = ''; - for ($i = 1; $i <= $blocks; ++$i) { - $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true); - // Iterations - for ($j = 1; $j < $iterations; ++$j) { - $ib ^= ($block = hash_hmac($algorithm, $block, $password, true)); + function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) + { + // Number of blocks needed to create the derived key + $blocks = ceil($length / strlen(hash($algorithm, null, true))); + $digest = ''; + for ($i = 1; $i <= $blocks; ++$i) { + $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true); + // Iterations + for ($j = 1; $j < $iterations; ++$j) { + $ib ^= ($block = hash_hmac($algorithm, $block, $password, true)); + } + $digest .= $ib; } - $digest .= $ib; + if (!$rawOutput) { + $digest = bin2hex($digest); + } + return substr($digest, 0, $length); } - if (!$rawOutput) { - $digest = bin2hex($digest); - } - return substr($digest, 0, $length); -} +} \ No newline at end of file