/** * Validates and decrypts string. * * @access public * @param string $string String to decrypt * @return string|boolean */ public function validateAndDecrypt($string) { if (empty($this->signer)) { throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to validate signed string.", [__METHOD__])); } $string = $this->signer->validate($string); return $string === false ? false : $this->decrypt($string); }
/** * Fetch signed cookie data. * * @access public * @param string $name Cookie name * @param mixed $default Default value * @return string */ public function signedCookie($name = null, $default = null) { if (empty($this->signer)) { throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to read signed cookies.", [__METHOD__])); } if (isset($this->cookies[$name]) && ($value = $this->signer->validate($this->cookies[$name])) !== false) { return $value; } else { return $default; } }
/** * */ public function testValidateInvalid() { $string = 'hello, world!'; $signer = new Signer('foobar'); $this->assertFalse($signer->validate(str_repeat('0', 64) . $string)); }