Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Crypt / Hash.php
bloba06f2c93049b5b2b76654588ffa04f26d868423e
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Crypt;
12 class Hash
14 const OUTPUT_STRING = false;
15 const OUTPUT_BINARY = true;
17 /**
18 * Last algorithm supported
20 * @var string|null
22 protected static $lastAlgorithmSupported;
24 /**
25 * @param string $hash
26 * @param string $data
27 * @param bool $output
28 * @throws Exception\InvalidArgumentException
29 * @return string
31 public static function compute($hash, $data, $output = self::OUTPUT_STRING)
33 if (!$hash || ($hash !== static::$lastAlgorithmSupported && !static::isSupported($hash))) {
34 throw new Exception\InvalidArgumentException(
35 'Hash algorithm provided is not supported on this PHP installation'
39 return hash($hash, $data, $output);
42 /**
43 * Get the output size according to the hash algorithm and the output format
45 * @param string $hash
46 * @param bool $output
47 * @return int
49 public static function getOutputSize($hash, $output = self::OUTPUT_STRING)
51 return strlen(static::compute($hash, 'data', $output));
54 /**
55 * Get the supported algorithm
57 * @return array
59 public static function getSupportedAlgorithms()
61 return hash_algos();
64 /**
65 * Is the hash algorithm supported?
67 * @param string $algorithm
68 * @return bool
70 public static function isSupported($algorithm)
72 if ($algorithm === static::$lastAlgorithmSupported) {
73 return true;
76 if (in_array(strtolower($algorithm), hash_algos(), true)) {
77 static::$lastAlgorithmSupported = $algorithm;
78 return true;
81 return false;
84 /**
85 * Clear the cache of last algorithm supported
87 public static function clearLastAlgorithmCache()
89 static::$lastAlgorithmSupported = null;