示例#1
0
 public function testIsSupportedAndCache()
 {
     Hash::clearLastAlgorithmCache();
     $this->assertAttributeEquals(null, 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     $algorithm = 'sha512';
     // cache value must be exactly equal to the original input
     $this->assertTrue(Hash::isSupported($algorithm));
     $this->assertAttributeEquals($algorithm, 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     $this->assertAttributeNotEquals('sHa512', 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     // cache value must be exactly equal to the first input (cache hit)
     Hash::isSupported('sha512');
     $this->assertAttributeEquals($algorithm, 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     // cache changes with a new algorithm
     $this->assertTrue(Hash::isSupported('sha1'));
     $this->assertAttributeEquals('sha1', 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     // cache don't change due wrong algorithm
     $this->assertFalse(Hash::isSupported('wrong'));
     $this->assertAttributeEquals('sha1', 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
     Hash::clearLastAlgorithmCache();
     $this->assertAttributeEquals(null, 'lastAlgorithmSupported', 'Zend\\Crypt\\Hash');
 }
示例#2
0
 /**
  * Set the hash algorithm for HMAC authentication
  *
  * @param  string $hash
  * @return BlockCipher
  * @throws Exception\InvalidArgumentException
  */
 public function setHashAlgorithm($hash)
 {
     if (!Hash::isSupported($hash)) {
         throw new Exception\InvalidArgumentException("The specified hash algorithm '{$hash}' is not supported by Zend\\Crypt\\Hash");
     }
     $this->hash = $hash;
     return $this;
 }