/** * Calculates hash * @param IInput $input * @return string * * @throws \Drahak\Restful\InvalidStateException */ public function calculate(IInput $input) { if (!$this->privateKey) { throw new InvalidStateException('Private key is not set'); } $dataString = $this->mapper->stringify($input->getData()); return hash_hmac(self::HASH, $dataString, $this->privateKey); }
/** * Authenticate request timeout * @param IInput $input * @return bool * * @throws RequestTimeoutException */ public function authenticate(IInput $input) { $timestamp = time(); $data = $input->getData(); if (!isset($data[$this->requestTimeKey]) || !$data[$this->requestTimeKey]) { throw new RequestTimeoutException('Request time not found in requested data.'); } $diff = $timestamp - $data[$this->requestTimeKey]; if ($diff > $this->timeout) { throw new RequestTimeoutException('Request timeout'); } return TRUE; }