Exemple #1
0
 /**
  * Is validator check valid?
  * @see Zend_Validate_Interface::isValid()
  */
 public function isValid($value, $context = null)
 {
     $context = array_change_key_case($context, CASE_LOWER);
     switch ($this->hashAlgorithm) {
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_HMAC_SHA512:
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_SHA512:
             $stringLength = 128;
             break;
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_MD5:
             $stringLength = 32;
             break;
         default:
             throw new WirecardCEE_Stdlib_Exception_UnexpectedValueException(sprintf("Used hash algorithm '%s' is not supported. MD5, SHA512, or HMAC_SHA512 are currently supported.", $this->hashAlgorithm));
             break;
     }
     if (strlen($value) != $stringLength) {
         return false;
     }
     if ($this->fingerprintOrderType == self::TYPE_FIXED) {
         $fingerprintOrder = $this->fingerprintOrder;
     } else {
         if (array_key_exists($this->fingerprintOrderField, $context)) {
             $fingerprintOrder = new WirecardCEE_Stdlib_FingerprintOrder(strtolower($context[$this->fingerprintOrderField]));
         } else {
             $this->_error(self::FINGERPRINTORDER_MISSING);
             return false;
         }
     }
     $fingerprintOrder->setOrder(array_map('strtolower', $this->fingerprintOrder->__toArray()));
     $fingerprintFields = array();
     foreach ($fingerprintOrder as $fingerprintFieldKey) {
         if ($fingerprintFieldKey == 'secret') {
             $fingerprintFields[$fingerprintFieldKey] = $this->secret;
         } else {
             $fingerprintFields[$fingerprintFieldKey] = isset($context[$fingerprintFieldKey]) ? $context[$fingerprintFieldKey] : '';
         }
     }
     if (!WirecardCEE_Stdlib_Fingerprint::compare($fingerprintFields, $fingerprintOrder, $value)) {
         $this->_error(self::INVALID);
         return false;
     }
     return true;
 }
 /**
  * @dataProvider fingerprintProvider
  */
 public function testFalseCompare($values, $fingerprintOrder, $hash)
 {
     $hash = md5($hash);
     $this->assertFalse(WirecardCEE_Stdlib_Fingerprint::compare($values, new WirecardCEE_Stdlib_FingerprintOrder($fingerprintOrder), $hash));
 }