/** * Testing all the getters and setters in the entity class */ public function testGettersAndSetters() { $array = $this->getDummyHmacData(); $this->entity->setData($array['data']); $this->entity->setKey($array['key']); $this->entity->setTime($array['time']); $this->entity->setHmac($array['hmac']); $this->assertTrue($array['data'] === $this->entity->getData()); $this->assertTrue($array['key'] === $this->entity->getKey()); $this->assertTrue($array['time'] === $this->entity->getTime()); $this->assertTrue($array['hmac'] === $this->entity->getHmac()); }
/** * Checks the HMAC key to make sure it is valid * * @param string $hmac * @return boolean */ public function isValid($hmac) { $this->adapter->encode(); if (time() - $this->entity->getTime() >= $this->ttl && $this->ttl != 0 || $hmac != $this->entity->getHmac()) { return false; } return true; }
/** * Encodes the HMAC based on the values that have been entered using the hash() function * * @throws HmacInvalidArgumentException * @return AbstractAdapter */ public function encode() { if (!$this->entity->isEncodable()) { throw new HmacInvalidArgumentException('The item is not encodable, make sure the key, time and data are set'); } $firstHash = $this->hash($this->entity->getData(), $this->entity->getTime(), $this->noFirstHashIterations); $secondHash = $this->hash($this->entity->getKey(), '', $this->noSecondHashIterations); $this->entity->setHmac($this->hash($firstHash, $secondHash, $this->noFinalHashIterations)); return $this; }
/** * Checks the HMAC key to make sure it is valid * * @param string $hmac * @return boolean */ public function isValid($hmac) { $this->adapter->encode(); return !(time() - $this->entity->getTime() >= $this->ttl && $this->ttl != 0 || $hmac != $this->entity->getHmac()); }