| @@ 51-65 (lines=15) @@ | ||
| 48 | * @param JWKParameter ...$params |
|
| 49 | * @throws \UnexpectedValueException If missing required parameter |
|
| 50 | */ |
|
| 51 | public function __construct(JWKParameter ...$params) { |
|
| 52 | parent::__construct(...$params); |
|
| 53 | foreach (self::MANAGED_PARAMS as $name) { |
|
| 54 | if (!$this->has($name)) { |
|
| 55 | throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { |
|
| 59 | throw new \UnexpectedValueException("Invalid key type."); |
|
| 60 | } |
|
| 61 | // cast ECC private key parameter to correct class |
|
| 62 | $key = RegisteredJWKParameter::PARAM_ECC_PRIVATE_KEY; |
|
| 63 | $this->_parameters[$key] = new ECCPrivateKeyParameter( |
|
| 64 | $this->_parameters[$key]->value()); |
|
| 65 | } |
|
| 66 | ||
| 67 | /** |
|
| 68 | * Initialize from ECPrivateKey. |
|
| @@ 60-74 (lines=15) @@ | ||
| 57 | * @param JWKParameter ...$params |
|
| 58 | * @throws \UnexpectedValueException If missing required parameter |
|
| 59 | */ |
|
| 60 | public function __construct(JWKParameter ...$params) { |
|
| 61 | parent::__construct(...$params); |
|
| 62 | foreach (self::MANAGED_PARAMS as $name) { |
|
| 63 | if (!$this->has($name)) { |
|
| 64 | throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_RSA) { |
|
| 68 | throw new \UnexpectedValueException("Invalid key type."); |
|
| 69 | } |
|
| 70 | // cast private exponent to correct class |
|
| 71 | $key = RegisteredJWKParameter::PARAM_PRIVATE_EXPONENT; |
|
| 72 | $this->_parameters[$key] = new PrivateExponentParameter( |
|
| 73 | $this->_parameters[$key]->value()); |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Initialize from RSAPrivateKey. |
|