From 7d3a1db46948869cee292c9663ec50e9a03f3eed Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 7 Sep 2015 19:52:17 +0200 Subject: [PATCH] Hash: Update incorrect documentation, use max line length 80. --- phpseclib/Crypt/Hash.php | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 09a6edcd..41afd6d9 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -1,23 +1,20 @@ * setKey('abcdefg'); * @@ -28,7 +25,9 @@ * @category Crypt * @package Hash * @author Jim Wigginton - * @copyright 2007 Jim Wigginton + * @copyright 2015 Jim Wigginton + * @author Andreas Fischer + * @copyright 2015 Andreas Fischer * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link http://phpseclib.sourceforge.net */ @@ -38,10 +37,9 @@ namespace phpseclib\Crypt; use phpseclib\Exception\UnsupportedAlgorithmException; /** - * Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions. - * * @package Hash * @author Jim Wigginton + * @author Andreas Fischer * @access public */ class Hash @@ -153,17 +151,25 @@ class Hash $this->length = 64; break; default: - // see if the hash isn't "officially" supported see if it can be "unofficially" supported and calculate the length accordingly + // see if the hash isn't "officially" supported see if it can + // be "unofficially" supported and calculate the length + // accordingly. if (in_array($hash, hash_algos())) { $this->length = strlen(hash($hash, '', true)); break; } - // if the hash algorithm doens't exist maybe it's a truncated hash. eg. md5-96 or some such - if (preg_match('#(-\d+)$#', $hash, $matches) && in_array($hash = substr($hash, 0, -strlen($matches[1])), hash_algos())) { - $this->length = abs($matches[1]) >> 3; - break; + // if the hash algorithm doens't exist maybe it's a truncated + // hash, e.g. whirlpool-12 or some such. + if (preg_match('#(-\d+)$#', $hash, $matches)) { + $hash = substr($hash, 0, -strlen($matches[1])); + if (in_array($hash, hash_algos())) { + $this->length = abs($matches[1]) >> 3; + break; + } } - throw new UnsupportedAlgorithmException("$hash is not a supported algorithm"); + throw new UnsupportedAlgorithmException( + "$hash is not a supported algorithm" + ); } $this->hash = $hash; @@ -182,7 +188,9 @@ class Hash hash_hmac($this->hash, $text, $this->key, true) : hash($this->hash, $text, true); - return strlen($output) > $this->length ? substr($output, 0, $this->length) : $output; + return strlen($output) > $this->length + ? substr($output, 0, $this->length) + : $output; } /**