Hash: Rename properly l to length.

This commit is contained in:
Andreas Fischer 2015-09-07 19:36:03 +02:00
parent 06a4cc5eba
commit b34de90818

View File

@ -62,7 +62,7 @@ class Hash
* @var int * @var int
* @access private * @access private
*/ */
var $l = false; var $length = false;
/** /**
* Hash Algorithm * Hash Algorithm
@ -135,33 +135,33 @@ class Hash
case 'sha256-96': case 'sha256-96':
case 'sha512-96': case 'sha512-96':
$hash = substr($hash, 0, -3); $hash = substr($hash, 0, -3);
$this->l = 12; // 96 / 8 = 12 $this->length = 12; // 96 / 8 = 12
break; break;
case 'md2': case 'md2':
case 'md5': case 'md5':
$this->l = 16; $this->length = 16;
break; break;
case 'sha1': case 'sha1':
$this->l = 20; $this->length = 20;
break; break;
case 'sha256': case 'sha256':
$this->l = 32; $this->length = 32;
break; break;
case 'sha384': case 'sha384':
$this->l = 48; $this->length = 48;
break; break;
case 'sha512': case 'sha512':
$this->l = 64; $this->length = 64;
break; break;
default: 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())) { if (in_array($hash, hash_algos())) {
$this->l = strlen(hash($hash, '', true)); $this->length = strlen(hash($hash, '', true));
break; break;
} }
// if the hash algorithm doens't exist maybe it's a truncated hash. eg. md5-96 or some such // 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())) { if (preg_match('#(-\d+)$#', $hash, $matches) && in_array($hash = substr($hash, 0, -strlen($matches[1])), hash_algos())) {
$this->l = abs($matches[1]) >> 3; $this->length = abs($matches[1]) >> 3;
break; break;
} }
throw new UnsupportedAlgorithmException("$hash is not a supported algorithm"); throw new UnsupportedAlgorithmException("$hash is not a supported algorithm");
@ -183,7 +183,7 @@ class Hash
hash_hmac($this->hash, $text, $this->key, true) : hash_hmac($this->hash, $text, $this->key, true) :
hash($this->hash, $text, true); hash($this->hash, $text, true);
return strlen($output) > $this->l ? substr($output, 0, $this->l) : $output; return strlen($output) > $this->length ? substr($output, 0, $this->length) : $output;
} }
/** /**
@ -194,6 +194,6 @@ class Hash
*/ */
function getLength() function getLength()
{ {
return $this->l; return $this->length;
} }
} }