| @@ 81-91 (lines=11) @@ | ||
| 78 | * @throws \UnexpectedValueException |
|
| 79 | * @return RSAESKeyAlgorithm |
|
| 80 | */ |
|
| 81 | public static function fromJWK(JWK $jwk, Header $header) { |
|
| 82 | $alg = JWA::deriveAlgorithmName($header, $jwk); |
|
| 83 | if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) { |
|
| 84 | throw new \UnexpectedValueException("Unsupported algorithm '$alg'."); |
|
| 85 | } |
|
| 86 | $cls = self::MAP_ALGO_TO_CLASS[$alg]; |
|
| 87 | if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) { |
|
| 88 | return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk)); |
|
| 89 | } |
|
| 90 | return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk)); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Initialize from a public key. |
|
| @@ 93-103 (lines=11) @@ | ||
| 90 | return new static($jwk->publicKey(), $jwk); |
|
| 91 | } |
|
| 92 | ||
| 93 | public static function fromJWK(JWK $jwk, Header $header) { |
|
| 94 | $alg = JWA::deriveAlgorithmName($header, $jwk); |
|
| 95 | if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) { |
|
| 96 | throw new \UnexpectedValueException("Unsupported algorithm '$alg'."); |
|
| 97 | } |
|
| 98 | $cls = self::MAP_ALGO_TO_CLASS[$alg]; |
|
| 99 | if ($jwk->has(...ECPrivateKeyJWK::MANAGED_PARAMS)) { |
|
| 100 | return $cls::fromPrivateKey(ECPrivateKeyJWK::fromJWK($jwk)); |
|
| 101 | } |
|
| 102 | return $cls::fromPublicKey(ECPublicKeyJWK::fromJWK($jwk)); |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * |
|
| @@ 74-84 (lines=11) @@ | ||
| 71 | * @throws \UnexpectedValueException |
|
| 72 | * @return RSASSAPKCS1Algorithm |
|
| 73 | */ |
|
| 74 | public static function fromJWK(JWK $jwk, Header $header) { |
|
| 75 | $alg = JWA::deriveAlgorithmName($header, $jwk); |
|
| 76 | if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) { |
|
| 77 | throw new \UnexpectedValueException("Unsupported algorithm '$alg'."); |
|
| 78 | } |
|
| 79 | $cls = self::MAP_ALGO_TO_CLASS[$alg]; |
|
| 80 | if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) { |
|
| 81 | return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk)); |
|
| 82 | } |
|
| 83 | return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk)); |
|
| 84 | } |
|
| 85 | ||
| 86 | public function headerParameters() { |
|
| 87 | return array(AlgorithmParameter::fromAlgorithm($this)); |
|