public function unsign($value, $max_age = null, $return_timestamp = false) { try { $result = parent::unsign($value); $sig_err = null; } catch (BadSignature $ex) { $sig_err = $ex; $result = $ex->payload; } if (strpos($result, $this->sep) === false) { if (!is_null($sig_err)) { throw $sig_err; } throw new BadTimeSignature("timestamp missing", $result); } list($timestamp, $value) = $this->pop_signature($result); $timestamp = $this->bytes_to_int($this->base64_decode_($timestamp)); # Signature is *not* okay. Raise a proper error now that we have # split the value and the timestamp. if (!is_null($sig_err)) { throw new BadTimeSignature((string) $sig_err, $value, $timestamp); } if (!is_null($max_age)) { $age = $this->get_timestamp() - $timestamp; if ($age > $max_age) { throw new SignatureExpired("Signature age {$age} > {$max_age} seconds", $value, $this->timestamp_to_datetime($timestamp)); } } if ($return_timestamp) { return array($value, $this->timestamp_to_datetime($timestamp)); } return $value; }
public function testSigner_deriveKeyByHMAC_shouldWork() { $s = new Signer("secret", 'salty', '.', 'hmac'); $foo = $s->sign("hello"); $this->assertEquals('hello.lcna0Kctpa6ne47lHrYKfTEsdew', $foo); $bar = $s->unsign($foo); $this->assertEquals('hello', $bar); }