コード例 #1
0
 /**
  * Encrypts and signs string.
  *
  * @access  public
  * @param   string  $string  String to encrypt
  * @return  string
  */
 public function encryptAndSign($string)
 {
     if (empty($this->signer)) {
         throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to sign string.", [__METHOD__]));
     }
     return $this->signer->sign($this->encrypt($string));
 }
コード例 #2
0
 /**
  * Sets a signed cookie.
  *
  * @access  public
  * @param   string               $name     Cookie name
  * @param   string               $value    Cookie value
  * @param   int                  $ttl      Time to live - if omitted or set to 0 the cookie will expire when the browser closes
  * @param   array                $options  Cookie options
  * @return  \mako\http\Response
  */
 public function signedCookie($name, $value, $ttl = 0, array $options = [])
 {
     if (empty($this->signer)) {
         throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to read signed cookies.", [__METHOD__]));
     }
     return $this->cookie($name, $this->signer->sign($value), $ttl, $options);
 }
コード例 #3
0
 /**
  *
  */
 public function testValidateValid()
 {
     $string = 'hello, world!';
     $signer = new Signer('foobar');
     $signed = $signer->sign($string);
     $this->assertEquals($string, $signer->validate($signed));
 }