Ejemplo n.º 1
0
 /**
  * Returns an instance of the algorithm class that will be used for sign.
  * @param JoseHeader $header
  * @param mixed $key
  * @return mixed
  */
 public static function getAlgorithmInstance(JoseHeader $header, $key = null)
 {
     switch ($header->getAlgorithm()) {
         case 'HS256':
         case 'HS384':
         case 'HS512':
             return new HmacAlgo(self::getSupportedAlgorithms()[$header->getAlgorithm()], $key);
             break;
         case 'RS256':
         case 'RS384':
         case 'RS512':
             return new RsassaPkcsAlgo(self::getSupportedAlgorithms()[$header->getAlgorithm()], $key);
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * @covers Jwa::getAlgorithmInstance
  */
 public function testGetAlgorithmInstance()
 {
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\HmacAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'HS256'])));
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\HmacAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'HS384'])));
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\HmacAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'HS512'])));
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\RsassaPkcsAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'RS256'])));
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\RsassaPkcsAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'RS384'])));
     $this->assertInstanceOf('iAchilles\\pjwt\\crypt\\RsassaPkcsAlgo', Jwa::getAlgorithmInstance(JoseHeader::parseFromArray(['alg' => 'RS512'])));
 }
Ejemplo n.º 3
0
 /**
  * @covers JoseHeader::toArray
  */
 public function testToArray()
 {
     $headers = ['alg' => 'HS256', 'jku' => 'https://localhost', 'jwk' => [], 'kid' => 'a', 'x5u' => 'https://localhost', 'x5c' => 'a', 'x5t' => 'a', 'x5t#S256' => 'a', 'typ' => 'a', 'cty' => 'a', 'crit' => ['a'], 'a' => 'b'];
     $header = JoseHeader::parseFromArray($headers);
     $this->assertEquals($headers, $header->toArray());
 }