Example #1
0
 /**
  * @brief Constructor
  *
  * @param String $algo The algorithm
  */
 public function __construct($algo)
 {
     $algo = strtolower($algo);
     // Check for support
     if (extension_loaded('hash')) {
         // We got the hashing support, so let's check if the algorithm is
         // supported.
         if (arr::hasValue(hash_algos(), $algo)) {
             $this->module = self::MOD_HASH;
             $this->algo = $algo;
             return;
         }
     }
     if (extension_loaded('mhash')) {
         // No hash support but mhash support, can it handle the algorithm?
         $num = mhash_count();
         for ($i = 0; $i <= $num; $i++) {
             if (mhash_get_hash_name($i) == $algo) {
                 $this->module = self::MOD_MHASH;
                 $this->algo = $algo;
                 return;
             }
         }
     }
     // Fall back on legacy spport here, is the algorithm one of the
     // by php supported ones?
     if (arr::hasValue(array('md5', 'sha1', 'crc32'), $algo)) {
         $this->module = self::MOD_PHP;
         $this->algo = $algo;
         return;
     }
     // No support, throw exception
     throw new SecurityException("Request for unsupported hash algorithm");
 }