示例#1
0
 /**
  * @param array              $header
  * @param \Jose\JWKInterface $key
  *
  * @return \Jose\Operation\SignatureInterface|null
  */
 protected function getAlgorithm(array $header, JWKInterface $key)
 {
     if (!array_key_exists('alg', $header)) {
         if (is_null($key->getAlgorithm())) {
             throw new \InvalidArgumentException("No 'alg' parameter set in the header or the key.");
         } else {
             $alg = $key->getAlgorithm();
         }
     } else {
         $alg = $header['alg'];
     }
     $algorithm = $this->getJWAManager()->getAlgorithm($alg);
     if (!$algorithm instanceof SignatureInterface) {
         throw new \RuntimeException("The algorithm '{$alg}' is not supported or does not implement SignatureInterface.");
     }
     return $algorithm;
 }
示例#2
0
 /**
  * @param array              $complete_header The complete header
  * @param \Jose\JWKInterface $key
  *
  * @return \Jose\Operation\SignatureInterface
  */
 protected function getSignatureAlgorithm(array $complete_header, JWKInterface $key)
 {
     if (!array_key_exists('alg', $complete_header)) {
         if (is_null($key->getAlgorithm())) {
             throw new \InvalidArgumentException("No 'alg' parameter set in the header or the key.");
         } else {
             $alg = $key->getAlgorithm();
         }
     } else {
         $alg = $complete_header['alg'];
     }
     if (!is_null($key->getAlgorithm()) && $key->getAlgorithm() !== $alg) {
         throw new \InvalidArgumentException("The algorithm '{$alg}' is allowed with this key.");
     }
     $signature_algorithm = $this->getJWAManager()->getAlgorithm($alg);
     if (!$signature_algorithm instanceof SignatureInterface) {
         throw new \InvalidArgumentException("The algorithm '{$alg}' is not supported.");
     }
     return $signature_algorithm;
 }