/**
* The number of bytes outputted by the hash algorithm
*/
- protected static $hashLength = array(
+ protected static $hashLength = [
true => null,
false => null,
- );
+ ];
/**
* Decide on the best acceptable hash algorithm we have available for hash()
}
$algos = hash_algos();
- $preference = array( 'whirlpool', 'sha256', 'sha1', 'md5' );
+ $preference = [ 'whirlpool', 'sha256', 'sha1', 'md5' ];
foreach ( $preference as $algorithm ) {
if ( in_array( $algorithm, $algos ) ) {
* Return the byte-length output of the hash algorithm we are
* using in self::hash and self::hmac.
*
- * @param boolean $raw True to return the length for binary data, false to
+ * @param bool $raw True to return the length for binary data, false to
* return for hex-encoded
* @return int Number of bytes the hash outputs
*/
* making use of the best hash algorithm that we have available.
*
* @param string $data
- * @param boolean $raw True to return binary data, false to return it hex-encoded
+ * @param bool $raw True to return binary data, false to return it hex-encoded
* @return string A hash of the data
*/
public static function hash( $data, $raw = true ) {
*
* @param string $data
* @param string $key
- * @param boolean $raw True to return binary data, false to return it hex-encoded
+ * @param bool $raw True to return binary data, false to return it hex-encoded
* @return string An hmac hash of the data + key
*/
public static function hmac( $data, $key, $raw = true ) {
+ if ( !is_string( $key ) ) {
+ // a fatal error in HHVM; an exception will at least give us a stack trace
+ throw new InvalidArgumentException( 'Invalid key type: ' . gettype( $key ) );
+ }
return hash_hmac( self::hashAlgo(), $data, $key, $raw );
}