@@ -11,567 +11,567 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | trait TypedJWK |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Whether parameters are present. |
|
| 16 | - * |
|
| 17 | - * @param string ...$names Parameter names |
|
| 18 | - * @return bool |
|
| 19 | - */ |
|
| 20 | - abstract public function has(string ...$names): bool; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Get a parameter. |
|
| 24 | - * |
|
| 25 | - * @param string $name Parameter name |
|
| 26 | - * @return JWKParameter |
|
| 27 | - */ |
|
| 28 | - abstract public function get(string $name): JWKParameter; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Check whether the algorithm parameter is present. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function hasAlgorithmParameter(): bool |
|
| 36 | - { |
|
| 37 | - return $this->has(Parameter\JWKParameter::P_ALG); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Get the algorithm parameter. |
|
| 42 | - * |
|
| 43 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 44 | - * @throws \LogicException If the parameter is not present |
|
| 45 | - * @return Parameter\AlgorithmParameter |
|
| 46 | - */ |
|
| 47 | - public function algorithmParameter(): Parameter\AlgorithmParameter |
|
| 48 | - { |
|
| 49 | - return self::_checkType($this->get(Parameter\JWKParameter::P_ALG), |
|
| 50 | - Parameter\AlgorithmParameter::class); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Check whether the curve parameter is present. |
|
| 55 | - * |
|
| 56 | - * @return bool |
|
| 57 | - */ |
|
| 58 | - public function hasCurveParameter(): bool |
|
| 59 | - { |
|
| 60 | - return $this->has(Parameter\JWKParameter::P_CRV); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get the curve parameter. |
|
| 65 | - * |
|
| 66 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 67 | - * @throws \LogicException If the parameter is not present |
|
| 68 | - * @return Parameter\CurveParameter |
|
| 69 | - */ |
|
| 70 | - public function curveParameter(): Parameter\CurveParameter |
|
| 71 | - { |
|
| 72 | - return self::_checkType($this->get(Parameter\JWKParameter::P_CRV), |
|
| 73 | - Parameter\CurveParameter::class); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Check whether the ECC private key parameter is present. |
|
| 78 | - * |
|
| 79 | - * @return bool |
|
| 80 | - */ |
|
| 81 | - public function hasECCPrivateKeyParameter(): bool |
|
| 82 | - { |
|
| 83 | - return $this->has(Parameter\JWKParameter::P_ECC_D); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the ECC private key parameter. |
|
| 88 | - * |
|
| 89 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 90 | - * @throws \LogicException If the parameter is not present |
|
| 91 | - * @return Parameter\ECCPrivateKeyParameter |
|
| 92 | - */ |
|
| 93 | - public function ECCPrivateKeyParameter(): Parameter\ECCPrivateKeyParameter |
|
| 94 | - { |
|
| 95 | - return self::_checkType($this->get(Parameter\JWKParameter::P_ECC_D), |
|
| 96 | - Parameter\ECCPrivateKeyParameter::class); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Check whether the exponent parameter is present. |
|
| 101 | - * |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - public function hasExponentParameter(): bool |
|
| 105 | - { |
|
| 106 | - return $this->has(Parameter\JWKParameter::P_E); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Get the exponent parameter. |
|
| 111 | - * |
|
| 112 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 113 | - * @throws \LogicException If the parameter is not present |
|
| 114 | - * @return Parameter\ExponentParameter |
|
| 115 | - */ |
|
| 116 | - public function exponentParameter(): Parameter\ExponentParameter |
|
| 117 | - { |
|
| 118 | - return self::_checkType($this->get(Parameter\JWKParameter::P_E), |
|
| 119 | - Parameter\ExponentParameter::class); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Check whether the first CRT coefficient parameter is present. |
|
| 124 | - * |
|
| 125 | - * @return bool |
|
| 126 | - */ |
|
| 127 | - public function hasFirstCRTCoefficientParameter(): bool |
|
| 128 | - { |
|
| 129 | - return $this->has(Parameter\JWKParameter::P_QI); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Get the first CRT coefficient parameter. |
|
| 134 | - * |
|
| 135 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 136 | - * @throws \LogicException If the parameter is not present |
|
| 137 | - * @return Parameter\FirstCRTCoefficientParameter |
|
| 138 | - */ |
|
| 139 | - public function firstCRTCoefficientParameter(): Parameter\FirstCRTCoefficientParameter |
|
| 140 | - { |
|
| 141 | - return self::_checkType($this->get(Parameter\JWKParameter::P_QI), |
|
| 142 | - Parameter\FirstCRTCoefficientParameter::class); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Check whether the first factor CRT exponent parameter is present. |
|
| 147 | - * |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - public function hasFirstFactorCRTExponentParameter(): bool |
|
| 151 | - { |
|
| 152 | - return $this->has(Parameter\JWKParameter::P_DP); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the first factor CRT exponent parameter. |
|
| 157 | - * |
|
| 158 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 159 | - * @throws \LogicException If the parameter is not present |
|
| 160 | - * @return Parameter\FirstFactorCRTExponentParameter |
|
| 161 | - */ |
|
| 162 | - public function firstFactorCRTExponentParameter(): Parameter\FirstFactorCRTExponentParameter |
|
| 163 | - { |
|
| 164 | - return self::_checkType($this->get(Parameter\JWKParameter::P_DP), |
|
| 165 | - Parameter\FirstFactorCRTExponentParameter::class); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Check whether the first prime factor parameter is present. |
|
| 170 | - * |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - public function hasFirstPrimeFactorParameter(): bool |
|
| 174 | - { |
|
| 175 | - return $this->has(Parameter\JWKParameter::P_P); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Get the first prime factor parameter. |
|
| 180 | - * |
|
| 181 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 182 | - * @throws \LogicException If the parameter is not present |
|
| 183 | - * @return Parameter\FirstPrimeFactorParameter |
|
| 184 | - */ |
|
| 185 | - public function firstPrimeFactorParameter(): Parameter\FirstPrimeFactorParameter |
|
| 186 | - { |
|
| 187 | - return self::_checkType($this->get(Parameter\JWKParameter::P_P), |
|
| 188 | - Parameter\FirstPrimeFactorParameter::class); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Check whether the key ID parameter is present. |
|
| 193 | - * |
|
| 194 | - * @return bool |
|
| 195 | - */ |
|
| 196 | - public function hasKeyIDParameter(): bool |
|
| 197 | - { |
|
| 198 | - return $this->has(Parameter\JWKParameter::P_KID); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Get the key ID parameter. |
|
| 203 | - * |
|
| 204 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 205 | - * @throws \LogicException If the parameter is not present |
|
| 206 | - * @return Parameter\KeyIDParameter |
|
| 207 | - */ |
|
| 208 | - public function keyIDParameter(): Parameter\KeyIDParameter |
|
| 209 | - { |
|
| 210 | - return self::_checkType($this->get(Parameter\JWKParameter::P_KID), |
|
| 211 | - Parameter\KeyIDParameter::class); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Check whether the key operations parameter is present. |
|
| 216 | - * |
|
| 217 | - * @return bool |
|
| 218 | - */ |
|
| 219 | - public function hasKeyOperationsParameter(): bool |
|
| 220 | - { |
|
| 221 | - return $this->has(Parameter\JWKParameter::P_KEY_OPS); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Get the key operations parameter. |
|
| 226 | - * |
|
| 227 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 228 | - * @throws \LogicException If the parameter is not present |
|
| 229 | - * @return Parameter\KeyOperationsParameter |
|
| 230 | - */ |
|
| 231 | - public function keyOperationsParameter(): Parameter\KeyOperationsParameter |
|
| 232 | - { |
|
| 233 | - return self::_checkType($this->get(Parameter\JWKParameter::P_KEY_OPS), |
|
| 234 | - Parameter\KeyOperationsParameter::class); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Check whether the key type parameter is present. |
|
| 239 | - * |
|
| 240 | - * @return bool |
|
| 241 | - */ |
|
| 242 | - public function hasKeyTypeParameter(): bool |
|
| 243 | - { |
|
| 244 | - return $this->has(Parameter\JWKParameter::P_KTY); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Get the key type parameter. |
|
| 249 | - * |
|
| 250 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 251 | - * @throws \LogicException If the parameter is not present |
|
| 252 | - * @return Parameter\KeyTypeParameter |
|
| 253 | - */ |
|
| 254 | - public function keyTypeParameter(): Parameter\KeyTypeParameter |
|
| 255 | - { |
|
| 256 | - return self::_checkType($this->get(Parameter\JWKParameter::P_KTY), |
|
| 257 | - Parameter\KeyTypeParameter::class); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Check whether the key value parameter is present. |
|
| 262 | - * |
|
| 263 | - * @return bool |
|
| 264 | - */ |
|
| 265 | - public function hasKeyValueParameter(): bool |
|
| 266 | - { |
|
| 267 | - return $this->has(Parameter\JWKParameter::P_K); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Get the key value parameter. |
|
| 272 | - * |
|
| 273 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 274 | - * @throws \LogicException If the parameter is not present |
|
| 275 | - * @return Parameter\KeyValueParameter |
|
| 276 | - */ |
|
| 277 | - public function keyValueParameter(): Parameter\KeyValueParameter |
|
| 278 | - { |
|
| 279 | - return self::_checkType($this->get(Parameter\JWKParameter::P_K), |
|
| 280 | - Parameter\KeyValueParameter::class); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Check whether the modulus parameter is present. |
|
| 285 | - * |
|
| 286 | - * @return bool |
|
| 287 | - */ |
|
| 288 | - public function hasModulusParameter(): bool |
|
| 289 | - { |
|
| 290 | - return $this->has(Parameter\JWKParameter::P_N); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the modulus parameter. |
|
| 295 | - * |
|
| 296 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 297 | - * @throws \LogicException If the parameter is not present |
|
| 298 | - * @return Parameter\ModulusParameter |
|
| 299 | - */ |
|
| 300 | - public function modulusParameter(): Parameter\ModulusParameter |
|
| 301 | - { |
|
| 302 | - return self::_checkType($this->get(Parameter\JWKParameter::P_N), |
|
| 303 | - Parameter\ModulusParameter::class); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Check whether the other primes info parameter is present. |
|
| 308 | - * |
|
| 309 | - * @return bool |
|
| 310 | - */ |
|
| 311 | - public function hasOtherPrimesInfoParameter(): bool |
|
| 312 | - { |
|
| 313 | - return $this->has(Parameter\JWKParameter::P_OTH); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Get the other primes info parameter. |
|
| 318 | - * |
|
| 319 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 320 | - * @throws \LogicException If the parameter is not present |
|
| 321 | - * @return Parameter\OtherPrimesInfoParameter |
|
| 322 | - */ |
|
| 323 | - public function otherPrimesInfoParameter(): Parameter\OtherPrimesInfoParameter |
|
| 324 | - { |
|
| 325 | - return self::_checkType($this->get(Parameter\JWKParameter::P_OTH), |
|
| 326 | - Parameter\OtherPrimesInfoParameter::class); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Check whether the private exponent parameter is present. |
|
| 331 | - * |
|
| 332 | - * @return bool |
|
| 333 | - */ |
|
| 334 | - public function hasPrivateExponentParameter(): bool |
|
| 335 | - { |
|
| 336 | - return $this->has(Parameter\JWKParameter::P_RSA_D); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Get the private exponent parameter. |
|
| 341 | - * |
|
| 342 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 343 | - * @throws \LogicException If the parameter is not present |
|
| 344 | - * @return Parameter\PrivateExponentParameter |
|
| 345 | - */ |
|
| 346 | - public function privateExponentParameter(): Parameter\PrivateExponentParameter |
|
| 347 | - { |
|
| 348 | - return self::_checkType($this->get(Parameter\JWKParameter::P_RSA_D), |
|
| 349 | - Parameter\PrivateExponentParameter::class); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Check whether the public key use parameter is present. |
|
| 354 | - * |
|
| 355 | - * @return bool |
|
| 356 | - */ |
|
| 357 | - public function hasPublicKeyUseParameter(): bool |
|
| 358 | - { |
|
| 359 | - return $this->has(Parameter\JWKParameter::P_USE); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Get the public key use parameter. |
|
| 364 | - * |
|
| 365 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 366 | - * @throws \LogicException If the parameter is not present |
|
| 367 | - * @return Parameter\PublicKeyUseParameter |
|
| 368 | - */ |
|
| 369 | - public function publicKeyUseParameter(): Parameter\PublicKeyUseParameter |
|
| 370 | - { |
|
| 371 | - return self::_checkType($this->get(Parameter\JWKParameter::P_USE), |
|
| 372 | - Parameter\PublicKeyUseParameter::class); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Check whether the second factor CRT exponent parameter is present. |
|
| 377 | - * |
|
| 378 | - * @return bool |
|
| 379 | - */ |
|
| 380 | - public function hasSecondFactorCRTExponentParameter(): bool |
|
| 381 | - { |
|
| 382 | - return $this->has(Parameter\JWKParameter::P_DQ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Get the second factor CRT exponent parameter. |
|
| 387 | - * |
|
| 388 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 389 | - * @throws \LogicException If the parameter is not present |
|
| 390 | - * @return Parameter\SecondFactorCRTExponentParameter |
|
| 391 | - */ |
|
| 392 | - public function secondFactorCRTExponentParameter(): Parameter\SecondFactorCRTExponentParameter |
|
| 393 | - { |
|
| 394 | - return self::_checkType($this->get(Parameter\JWKParameter::P_DQ), |
|
| 395 | - Parameter\SecondFactorCRTExponentParameter::class); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Check whether the second prime factor parameter is present. |
|
| 400 | - * |
|
| 401 | - * @return bool |
|
| 402 | - */ |
|
| 403 | - public function hasSecondPrimeFactorParameter(): bool |
|
| 404 | - { |
|
| 405 | - return $this->has(Parameter\JWKParameter::P_Q); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Get the second prime factor parameter. |
|
| 410 | - * |
|
| 411 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 412 | - * @throws \LogicException If the parameter is not present |
|
| 413 | - * @return Parameter\SecondPrimeFactorParameter |
|
| 414 | - */ |
|
| 415 | - public function secondPrimeFactorParameter(): Parameter\SecondPrimeFactorParameter |
|
| 416 | - { |
|
| 417 | - return self::_checkType($this->get(Parameter\JWKParameter::P_Q), |
|
| 418 | - Parameter\SecondPrimeFactorParameter::class); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Check whether the X.509 certificate chain parameter is present. |
|
| 423 | - * |
|
| 424 | - * @return bool |
|
| 425 | - */ |
|
| 426 | - public function hasX509CertificateChainParameter(): bool |
|
| 427 | - { |
|
| 428 | - return $this->has(Parameter\JWKParameter::P_X5C); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Get the X.509 certificate chain parameter. |
|
| 433 | - * |
|
| 434 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 435 | - * @throws \LogicException If the parameter is not present |
|
| 436 | - * @return Parameter\X509CertificateChainParameter |
|
| 437 | - */ |
|
| 438 | - public function X509CertificateChainParameter(): Parameter\X509CertificateChainParameter |
|
| 439 | - { |
|
| 440 | - return self::_checkType($this->get(Parameter\JWKParameter::P_X5C), |
|
| 441 | - Parameter\X509CertificateChainParameter::class); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
| 446 | - * present. |
|
| 447 | - * |
|
| 448 | - * @return bool |
|
| 449 | - */ |
|
| 450 | - public function hasX509CertificateSHA1ThumbprintParameter(): bool |
|
| 451 | - { |
|
| 452 | - return $this->has(Parameter\JWKParameter::P_X5T); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
| 457 | - * |
|
| 458 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 459 | - * @throws \LogicException If the parameter is not present |
|
| 460 | - * @return Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 461 | - */ |
|
| 462 | - public function X509CertificateSHA1ThumbprintParameter(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 463 | - { |
|
| 464 | - return self::_checkType($this->get(Parameter\JWKParameter::P_X5T), |
|
| 465 | - Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
| 470 | - * present. |
|
| 471 | - * |
|
| 472 | - * @return bool |
|
| 473 | - */ |
|
| 474 | - public function hasX509CertificateSHA256ThumbprintParameter(): bool |
|
| 475 | - { |
|
| 476 | - return $this->has(Parameter\JWKParameter::P_X5TS256); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
| 481 | - * |
|
| 482 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 483 | - * @throws \LogicException If the parameter is not present |
|
| 484 | - * @return Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 485 | - */ |
|
| 486 | - public function X509CertificateSHA256ThumbprintParameter(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 487 | - { |
|
| 488 | - return self::_checkType($this->get(Parameter\JWKParameter::P_X5TS256), |
|
| 489 | - Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Check whether the X.509 URL parameter is present. |
|
| 494 | - * |
|
| 495 | - * @return bool |
|
| 496 | - */ |
|
| 497 | - public function hasX509URLParameter(): bool |
|
| 498 | - { |
|
| 499 | - return $this->has(Parameter\JWKParameter::P_X5U); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Get the X.509 URL parameter. |
|
| 504 | - * |
|
| 505 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 506 | - * @throws \LogicException If the parameter is not present |
|
| 507 | - * @return Parameter\X509URLParameter |
|
| 508 | - */ |
|
| 509 | - public function X509URLParameter(): Parameter\X509URLParameter |
|
| 510 | - { |
|
| 511 | - return self::_checkType($this->get(Parameter\JWKParameter::P_X5U), |
|
| 512 | - Parameter\X509URLParameter::class); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Check whether the X coordinate parameter is present. |
|
| 517 | - * |
|
| 518 | - * @return bool |
|
| 519 | - */ |
|
| 520 | - public function hasXCoordinateParameter(): bool |
|
| 521 | - { |
|
| 522 | - return $this->has(Parameter\JWKParameter::P_X); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Get the X coordinate parameter. |
|
| 527 | - * |
|
| 528 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 529 | - * @throws \LogicException If the parameter is not present |
|
| 530 | - * @return Parameter\XCoordinateParameter |
|
| 531 | - */ |
|
| 532 | - public function XCoordinateParameter(): Parameter\XCoordinateParameter |
|
| 533 | - { |
|
| 534 | - return self::_checkType($this->get(Parameter\JWKParameter::P_X), |
|
| 535 | - Parameter\XCoordinateParameter::class); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Check whether the Y coordinate parameter is present. |
|
| 540 | - * |
|
| 541 | - * @return bool |
|
| 542 | - */ |
|
| 543 | - public function hasYCoordinateParameter(): bool |
|
| 544 | - { |
|
| 545 | - return $this->has(Parameter\JWKParameter::P_Y); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Get the Y coordinate parameter. |
|
| 550 | - * |
|
| 551 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 552 | - * @throws \LogicException If the parameter is not present |
|
| 553 | - * @return Parameter\YCoordinateParameter |
|
| 554 | - */ |
|
| 555 | - public function YCoordinateParameter(): Parameter\YCoordinateParameter |
|
| 556 | - { |
|
| 557 | - return self::_checkType($this->get(Parameter\JWKParameter::P_Y), |
|
| 558 | - Parameter\YCoordinateParameter::class); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Check that the parameter is an instance of the given class. |
|
| 563 | - * |
|
| 564 | - * @param Parameter\JWKParameter $param Parameter |
|
| 565 | - * @param string $cls Class name |
|
| 566 | - * @throws \UnexpectedValueException |
|
| 567 | - * @return Parameter\JWKParameter |
|
| 568 | - */ |
|
| 569 | - private static function _checkType(Parameter\JWKParameter $param, string $cls): Parameter\JWKParameter |
|
| 570 | - { |
|
| 571 | - if (!$param instanceof $cls) { |
|
| 572 | - throw new \UnexpectedValueException( |
|
| 573 | - "$cls expected, got " . get_class($param)); |
|
| 574 | - } |
|
| 575 | - return $param; |
|
| 576 | - } |
|
| 14 | + /** |
|
| 15 | + * Whether parameters are present. |
|
| 16 | + * |
|
| 17 | + * @param string ...$names Parameter names |
|
| 18 | + * @return bool |
|
| 19 | + */ |
|
| 20 | + abstract public function has(string ...$names): bool; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Get a parameter. |
|
| 24 | + * |
|
| 25 | + * @param string $name Parameter name |
|
| 26 | + * @return JWKParameter |
|
| 27 | + */ |
|
| 28 | + abstract public function get(string $name): JWKParameter; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Check whether the algorithm parameter is present. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function hasAlgorithmParameter(): bool |
|
| 36 | + { |
|
| 37 | + return $this->has(Parameter\JWKParameter::P_ALG); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Get the algorithm parameter. |
|
| 42 | + * |
|
| 43 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 44 | + * @throws \LogicException If the parameter is not present |
|
| 45 | + * @return Parameter\AlgorithmParameter |
|
| 46 | + */ |
|
| 47 | + public function algorithmParameter(): Parameter\AlgorithmParameter |
|
| 48 | + { |
|
| 49 | + return self::_checkType($this->get(Parameter\JWKParameter::P_ALG), |
|
| 50 | + Parameter\AlgorithmParameter::class); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Check whether the curve parameter is present. |
|
| 55 | + * |
|
| 56 | + * @return bool |
|
| 57 | + */ |
|
| 58 | + public function hasCurveParameter(): bool |
|
| 59 | + { |
|
| 60 | + return $this->has(Parameter\JWKParameter::P_CRV); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get the curve parameter. |
|
| 65 | + * |
|
| 66 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 67 | + * @throws \LogicException If the parameter is not present |
|
| 68 | + * @return Parameter\CurveParameter |
|
| 69 | + */ |
|
| 70 | + public function curveParameter(): Parameter\CurveParameter |
|
| 71 | + { |
|
| 72 | + return self::_checkType($this->get(Parameter\JWKParameter::P_CRV), |
|
| 73 | + Parameter\CurveParameter::class); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Check whether the ECC private key parameter is present. |
|
| 78 | + * |
|
| 79 | + * @return bool |
|
| 80 | + */ |
|
| 81 | + public function hasECCPrivateKeyParameter(): bool |
|
| 82 | + { |
|
| 83 | + return $this->has(Parameter\JWKParameter::P_ECC_D); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the ECC private key parameter. |
|
| 88 | + * |
|
| 89 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 90 | + * @throws \LogicException If the parameter is not present |
|
| 91 | + * @return Parameter\ECCPrivateKeyParameter |
|
| 92 | + */ |
|
| 93 | + public function ECCPrivateKeyParameter(): Parameter\ECCPrivateKeyParameter |
|
| 94 | + { |
|
| 95 | + return self::_checkType($this->get(Parameter\JWKParameter::P_ECC_D), |
|
| 96 | + Parameter\ECCPrivateKeyParameter::class); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Check whether the exponent parameter is present. |
|
| 101 | + * |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + public function hasExponentParameter(): bool |
|
| 105 | + { |
|
| 106 | + return $this->has(Parameter\JWKParameter::P_E); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Get the exponent parameter. |
|
| 111 | + * |
|
| 112 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 113 | + * @throws \LogicException If the parameter is not present |
|
| 114 | + * @return Parameter\ExponentParameter |
|
| 115 | + */ |
|
| 116 | + public function exponentParameter(): Parameter\ExponentParameter |
|
| 117 | + { |
|
| 118 | + return self::_checkType($this->get(Parameter\JWKParameter::P_E), |
|
| 119 | + Parameter\ExponentParameter::class); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Check whether the first CRT coefficient parameter is present. |
|
| 124 | + * |
|
| 125 | + * @return bool |
|
| 126 | + */ |
|
| 127 | + public function hasFirstCRTCoefficientParameter(): bool |
|
| 128 | + { |
|
| 129 | + return $this->has(Parameter\JWKParameter::P_QI); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Get the first CRT coefficient parameter. |
|
| 134 | + * |
|
| 135 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 136 | + * @throws \LogicException If the parameter is not present |
|
| 137 | + * @return Parameter\FirstCRTCoefficientParameter |
|
| 138 | + */ |
|
| 139 | + public function firstCRTCoefficientParameter(): Parameter\FirstCRTCoefficientParameter |
|
| 140 | + { |
|
| 141 | + return self::_checkType($this->get(Parameter\JWKParameter::P_QI), |
|
| 142 | + Parameter\FirstCRTCoefficientParameter::class); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Check whether the first factor CRT exponent parameter is present. |
|
| 147 | + * |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + public function hasFirstFactorCRTExponentParameter(): bool |
|
| 151 | + { |
|
| 152 | + return $this->has(Parameter\JWKParameter::P_DP); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the first factor CRT exponent parameter. |
|
| 157 | + * |
|
| 158 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 159 | + * @throws \LogicException If the parameter is not present |
|
| 160 | + * @return Parameter\FirstFactorCRTExponentParameter |
|
| 161 | + */ |
|
| 162 | + public function firstFactorCRTExponentParameter(): Parameter\FirstFactorCRTExponentParameter |
|
| 163 | + { |
|
| 164 | + return self::_checkType($this->get(Parameter\JWKParameter::P_DP), |
|
| 165 | + Parameter\FirstFactorCRTExponentParameter::class); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Check whether the first prime factor parameter is present. |
|
| 170 | + * |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + public function hasFirstPrimeFactorParameter(): bool |
|
| 174 | + { |
|
| 175 | + return $this->has(Parameter\JWKParameter::P_P); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Get the first prime factor parameter. |
|
| 180 | + * |
|
| 181 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 182 | + * @throws \LogicException If the parameter is not present |
|
| 183 | + * @return Parameter\FirstPrimeFactorParameter |
|
| 184 | + */ |
|
| 185 | + public function firstPrimeFactorParameter(): Parameter\FirstPrimeFactorParameter |
|
| 186 | + { |
|
| 187 | + return self::_checkType($this->get(Parameter\JWKParameter::P_P), |
|
| 188 | + Parameter\FirstPrimeFactorParameter::class); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Check whether the key ID parameter is present. |
|
| 193 | + * |
|
| 194 | + * @return bool |
|
| 195 | + */ |
|
| 196 | + public function hasKeyIDParameter(): bool |
|
| 197 | + { |
|
| 198 | + return $this->has(Parameter\JWKParameter::P_KID); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Get the key ID parameter. |
|
| 203 | + * |
|
| 204 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 205 | + * @throws \LogicException If the parameter is not present |
|
| 206 | + * @return Parameter\KeyIDParameter |
|
| 207 | + */ |
|
| 208 | + public function keyIDParameter(): Parameter\KeyIDParameter |
|
| 209 | + { |
|
| 210 | + return self::_checkType($this->get(Parameter\JWKParameter::P_KID), |
|
| 211 | + Parameter\KeyIDParameter::class); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Check whether the key operations parameter is present. |
|
| 216 | + * |
|
| 217 | + * @return bool |
|
| 218 | + */ |
|
| 219 | + public function hasKeyOperationsParameter(): bool |
|
| 220 | + { |
|
| 221 | + return $this->has(Parameter\JWKParameter::P_KEY_OPS); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Get the key operations parameter. |
|
| 226 | + * |
|
| 227 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 228 | + * @throws \LogicException If the parameter is not present |
|
| 229 | + * @return Parameter\KeyOperationsParameter |
|
| 230 | + */ |
|
| 231 | + public function keyOperationsParameter(): Parameter\KeyOperationsParameter |
|
| 232 | + { |
|
| 233 | + return self::_checkType($this->get(Parameter\JWKParameter::P_KEY_OPS), |
|
| 234 | + Parameter\KeyOperationsParameter::class); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Check whether the key type parameter is present. |
|
| 239 | + * |
|
| 240 | + * @return bool |
|
| 241 | + */ |
|
| 242 | + public function hasKeyTypeParameter(): bool |
|
| 243 | + { |
|
| 244 | + return $this->has(Parameter\JWKParameter::P_KTY); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Get the key type parameter. |
|
| 249 | + * |
|
| 250 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 251 | + * @throws \LogicException If the parameter is not present |
|
| 252 | + * @return Parameter\KeyTypeParameter |
|
| 253 | + */ |
|
| 254 | + public function keyTypeParameter(): Parameter\KeyTypeParameter |
|
| 255 | + { |
|
| 256 | + return self::_checkType($this->get(Parameter\JWKParameter::P_KTY), |
|
| 257 | + Parameter\KeyTypeParameter::class); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Check whether the key value parameter is present. |
|
| 262 | + * |
|
| 263 | + * @return bool |
|
| 264 | + */ |
|
| 265 | + public function hasKeyValueParameter(): bool |
|
| 266 | + { |
|
| 267 | + return $this->has(Parameter\JWKParameter::P_K); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Get the key value parameter. |
|
| 272 | + * |
|
| 273 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 274 | + * @throws \LogicException If the parameter is not present |
|
| 275 | + * @return Parameter\KeyValueParameter |
|
| 276 | + */ |
|
| 277 | + public function keyValueParameter(): Parameter\KeyValueParameter |
|
| 278 | + { |
|
| 279 | + return self::_checkType($this->get(Parameter\JWKParameter::P_K), |
|
| 280 | + Parameter\KeyValueParameter::class); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Check whether the modulus parameter is present. |
|
| 285 | + * |
|
| 286 | + * @return bool |
|
| 287 | + */ |
|
| 288 | + public function hasModulusParameter(): bool |
|
| 289 | + { |
|
| 290 | + return $this->has(Parameter\JWKParameter::P_N); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the modulus parameter. |
|
| 295 | + * |
|
| 296 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 297 | + * @throws \LogicException If the parameter is not present |
|
| 298 | + * @return Parameter\ModulusParameter |
|
| 299 | + */ |
|
| 300 | + public function modulusParameter(): Parameter\ModulusParameter |
|
| 301 | + { |
|
| 302 | + return self::_checkType($this->get(Parameter\JWKParameter::P_N), |
|
| 303 | + Parameter\ModulusParameter::class); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Check whether the other primes info parameter is present. |
|
| 308 | + * |
|
| 309 | + * @return bool |
|
| 310 | + */ |
|
| 311 | + public function hasOtherPrimesInfoParameter(): bool |
|
| 312 | + { |
|
| 313 | + return $this->has(Parameter\JWKParameter::P_OTH); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Get the other primes info parameter. |
|
| 318 | + * |
|
| 319 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 320 | + * @throws \LogicException If the parameter is not present |
|
| 321 | + * @return Parameter\OtherPrimesInfoParameter |
|
| 322 | + */ |
|
| 323 | + public function otherPrimesInfoParameter(): Parameter\OtherPrimesInfoParameter |
|
| 324 | + { |
|
| 325 | + return self::_checkType($this->get(Parameter\JWKParameter::P_OTH), |
|
| 326 | + Parameter\OtherPrimesInfoParameter::class); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Check whether the private exponent parameter is present. |
|
| 331 | + * |
|
| 332 | + * @return bool |
|
| 333 | + */ |
|
| 334 | + public function hasPrivateExponentParameter(): bool |
|
| 335 | + { |
|
| 336 | + return $this->has(Parameter\JWKParameter::P_RSA_D); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Get the private exponent parameter. |
|
| 341 | + * |
|
| 342 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 343 | + * @throws \LogicException If the parameter is not present |
|
| 344 | + * @return Parameter\PrivateExponentParameter |
|
| 345 | + */ |
|
| 346 | + public function privateExponentParameter(): Parameter\PrivateExponentParameter |
|
| 347 | + { |
|
| 348 | + return self::_checkType($this->get(Parameter\JWKParameter::P_RSA_D), |
|
| 349 | + Parameter\PrivateExponentParameter::class); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Check whether the public key use parameter is present. |
|
| 354 | + * |
|
| 355 | + * @return bool |
|
| 356 | + */ |
|
| 357 | + public function hasPublicKeyUseParameter(): bool |
|
| 358 | + { |
|
| 359 | + return $this->has(Parameter\JWKParameter::P_USE); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Get the public key use parameter. |
|
| 364 | + * |
|
| 365 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 366 | + * @throws \LogicException If the parameter is not present |
|
| 367 | + * @return Parameter\PublicKeyUseParameter |
|
| 368 | + */ |
|
| 369 | + public function publicKeyUseParameter(): Parameter\PublicKeyUseParameter |
|
| 370 | + { |
|
| 371 | + return self::_checkType($this->get(Parameter\JWKParameter::P_USE), |
|
| 372 | + Parameter\PublicKeyUseParameter::class); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Check whether the second factor CRT exponent parameter is present. |
|
| 377 | + * |
|
| 378 | + * @return bool |
|
| 379 | + */ |
|
| 380 | + public function hasSecondFactorCRTExponentParameter(): bool |
|
| 381 | + { |
|
| 382 | + return $this->has(Parameter\JWKParameter::P_DQ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Get the second factor CRT exponent parameter. |
|
| 387 | + * |
|
| 388 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 389 | + * @throws \LogicException If the parameter is not present |
|
| 390 | + * @return Parameter\SecondFactorCRTExponentParameter |
|
| 391 | + */ |
|
| 392 | + public function secondFactorCRTExponentParameter(): Parameter\SecondFactorCRTExponentParameter |
|
| 393 | + { |
|
| 394 | + return self::_checkType($this->get(Parameter\JWKParameter::P_DQ), |
|
| 395 | + Parameter\SecondFactorCRTExponentParameter::class); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Check whether the second prime factor parameter is present. |
|
| 400 | + * |
|
| 401 | + * @return bool |
|
| 402 | + */ |
|
| 403 | + public function hasSecondPrimeFactorParameter(): bool |
|
| 404 | + { |
|
| 405 | + return $this->has(Parameter\JWKParameter::P_Q); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Get the second prime factor parameter. |
|
| 410 | + * |
|
| 411 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 412 | + * @throws \LogicException If the parameter is not present |
|
| 413 | + * @return Parameter\SecondPrimeFactorParameter |
|
| 414 | + */ |
|
| 415 | + public function secondPrimeFactorParameter(): Parameter\SecondPrimeFactorParameter |
|
| 416 | + { |
|
| 417 | + return self::_checkType($this->get(Parameter\JWKParameter::P_Q), |
|
| 418 | + Parameter\SecondPrimeFactorParameter::class); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Check whether the X.509 certificate chain parameter is present. |
|
| 423 | + * |
|
| 424 | + * @return bool |
|
| 425 | + */ |
|
| 426 | + public function hasX509CertificateChainParameter(): bool |
|
| 427 | + { |
|
| 428 | + return $this->has(Parameter\JWKParameter::P_X5C); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Get the X.509 certificate chain parameter. |
|
| 433 | + * |
|
| 434 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 435 | + * @throws \LogicException If the parameter is not present |
|
| 436 | + * @return Parameter\X509CertificateChainParameter |
|
| 437 | + */ |
|
| 438 | + public function X509CertificateChainParameter(): Parameter\X509CertificateChainParameter |
|
| 439 | + { |
|
| 440 | + return self::_checkType($this->get(Parameter\JWKParameter::P_X5C), |
|
| 441 | + Parameter\X509CertificateChainParameter::class); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
| 446 | + * present. |
|
| 447 | + * |
|
| 448 | + * @return bool |
|
| 449 | + */ |
|
| 450 | + public function hasX509CertificateSHA1ThumbprintParameter(): bool |
|
| 451 | + { |
|
| 452 | + return $this->has(Parameter\JWKParameter::P_X5T); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
| 457 | + * |
|
| 458 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 459 | + * @throws \LogicException If the parameter is not present |
|
| 460 | + * @return Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 461 | + */ |
|
| 462 | + public function X509CertificateSHA1ThumbprintParameter(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 463 | + { |
|
| 464 | + return self::_checkType($this->get(Parameter\JWKParameter::P_X5T), |
|
| 465 | + Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
| 470 | + * present. |
|
| 471 | + * |
|
| 472 | + * @return bool |
|
| 473 | + */ |
|
| 474 | + public function hasX509CertificateSHA256ThumbprintParameter(): bool |
|
| 475 | + { |
|
| 476 | + return $this->has(Parameter\JWKParameter::P_X5TS256); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
| 481 | + * |
|
| 482 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 483 | + * @throws \LogicException If the parameter is not present |
|
| 484 | + * @return Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 485 | + */ |
|
| 486 | + public function X509CertificateSHA256ThumbprintParameter(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 487 | + { |
|
| 488 | + return self::_checkType($this->get(Parameter\JWKParameter::P_X5TS256), |
|
| 489 | + Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Check whether the X.509 URL parameter is present. |
|
| 494 | + * |
|
| 495 | + * @return bool |
|
| 496 | + */ |
|
| 497 | + public function hasX509URLParameter(): bool |
|
| 498 | + { |
|
| 499 | + return $this->has(Parameter\JWKParameter::P_X5U); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Get the X.509 URL parameter. |
|
| 504 | + * |
|
| 505 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 506 | + * @throws \LogicException If the parameter is not present |
|
| 507 | + * @return Parameter\X509URLParameter |
|
| 508 | + */ |
|
| 509 | + public function X509URLParameter(): Parameter\X509URLParameter |
|
| 510 | + { |
|
| 511 | + return self::_checkType($this->get(Parameter\JWKParameter::P_X5U), |
|
| 512 | + Parameter\X509URLParameter::class); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Check whether the X coordinate parameter is present. |
|
| 517 | + * |
|
| 518 | + * @return bool |
|
| 519 | + */ |
|
| 520 | + public function hasXCoordinateParameter(): bool |
|
| 521 | + { |
|
| 522 | + return $this->has(Parameter\JWKParameter::P_X); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Get the X coordinate parameter. |
|
| 527 | + * |
|
| 528 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 529 | + * @throws \LogicException If the parameter is not present |
|
| 530 | + * @return Parameter\XCoordinateParameter |
|
| 531 | + */ |
|
| 532 | + public function XCoordinateParameter(): Parameter\XCoordinateParameter |
|
| 533 | + { |
|
| 534 | + return self::_checkType($this->get(Parameter\JWKParameter::P_X), |
|
| 535 | + Parameter\XCoordinateParameter::class); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Check whether the Y coordinate parameter is present. |
|
| 540 | + * |
|
| 541 | + * @return bool |
|
| 542 | + */ |
|
| 543 | + public function hasYCoordinateParameter(): bool |
|
| 544 | + { |
|
| 545 | + return $this->has(Parameter\JWKParameter::P_Y); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Get the Y coordinate parameter. |
|
| 550 | + * |
|
| 551 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 552 | + * @throws \LogicException If the parameter is not present |
|
| 553 | + * @return Parameter\YCoordinateParameter |
|
| 554 | + */ |
|
| 555 | + public function YCoordinateParameter(): Parameter\YCoordinateParameter |
|
| 556 | + { |
|
| 557 | + return self::_checkType($this->get(Parameter\JWKParameter::P_Y), |
|
| 558 | + Parameter\YCoordinateParameter::class); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Check that the parameter is an instance of the given class. |
|
| 563 | + * |
|
| 564 | + * @param Parameter\JWKParameter $param Parameter |
|
| 565 | + * @param string $cls Class name |
|
| 566 | + * @throws \UnexpectedValueException |
|
| 567 | + * @return Parameter\JWKParameter |
|
| 568 | + */ |
|
| 569 | + private static function _checkType(Parameter\JWKParameter $param, string $cls): Parameter\JWKParameter |
|
| 570 | + { |
|
| 571 | + if (!$param instanceof $cls) { |
|
| 572 | + throw new \UnexpectedValueException( |
|
| 573 | + "$cls expected, got " . get_class($param)); |
|
| 574 | + } |
|
| 575 | + return $param; |
|
| 576 | + } |
|
| 577 | 577 | } |
@@ -17,60 +17,60 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class SymmetricKeyJWK extends JWK |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Parameter names managed by this class. |
|
| 22 | - * |
|
| 23 | - * @internal |
|
| 24 | - * |
|
| 25 | - * @var string[] |
|
| 26 | - */ |
|
| 27 | - const MANAGED_PARAMS = array( |
|
| 28 | - /* @formatter:off */ |
|
| 29 | - JWKParameter::PARAM_KEY_TYPE, |
|
| 30 | - JWKParameter::PARAM_KEY_VALUE |
|
| 31 | - /* @formatter:on */ |
|
| 32 | - ); |
|
| 20 | + /** |
|
| 21 | + * Parameter names managed by this class. |
|
| 22 | + * |
|
| 23 | + * @internal |
|
| 24 | + * |
|
| 25 | + * @var string[] |
|
| 26 | + */ |
|
| 27 | + const MANAGED_PARAMS = array( |
|
| 28 | + /* @formatter:off */ |
|
| 29 | + JWKParameter::PARAM_KEY_TYPE, |
|
| 30 | + JWKParameter::PARAM_KEY_VALUE |
|
| 31 | + /* @formatter:on */ |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param JWKParameter ...$params |
|
| 38 | - * @throws \UnexpectedValueException If missing required parameter |
|
| 39 | - */ |
|
| 40 | - public function __construct(JWKParameter ...$params) |
|
| 41 | - { |
|
| 42 | - parent::__construct(...$params); |
|
| 43 | - foreach (self::MANAGED_PARAMS as $name) { |
|
| 44 | - if (!$this->has($name)) { |
|
| 45 | - throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) { |
|
| 49 | - throw new \UnexpectedValueException("Invalid key type."); |
|
| 50 | - } |
|
| 51 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param JWKParameter ...$params |
|
| 38 | + * @throws \UnexpectedValueException If missing required parameter |
|
| 39 | + */ |
|
| 40 | + public function __construct(JWKParameter ...$params) |
|
| 41 | + { |
|
| 42 | + parent::__construct(...$params); |
|
| 43 | + foreach (self::MANAGED_PARAMS as $name) { |
|
| 44 | + if (!$this->has($name)) { |
|
| 45 | + throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) { |
|
| 49 | + throw new \UnexpectedValueException("Invalid key type."); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Initialize from a key string. |
|
| 55 | - * |
|
| 56 | - * @param string $key Symmetric key |
|
| 57 | - * @param JWKParameter ...$params Optional additional parameters |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public static function fromKey(string $key, JWKParameter ...$params): self |
|
| 61 | - { |
|
| 62 | - $params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT); |
|
| 63 | - $params[] = KeyValueParameter::fromString($key); |
|
| 64 | - return new self(...$params); |
|
| 65 | - } |
|
| 53 | + /** |
|
| 54 | + * Initialize from a key string. |
|
| 55 | + * |
|
| 56 | + * @param string $key Symmetric key |
|
| 57 | + * @param JWKParameter ...$params Optional additional parameters |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public static function fromKey(string $key, JWKParameter ...$params): self |
|
| 61 | + { |
|
| 62 | + $params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT); |
|
| 63 | + $params[] = KeyValueParameter::fromString($key); |
|
| 64 | + return new self(...$params); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get the symmetric key. |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function key(): string |
|
| 73 | - { |
|
| 74 | - return Base64::urlDecode($this->keyValueParameter()->value()); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Get the symmetric key. |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function key(): string |
|
| 73 | + { |
|
| 74 | + return Base64::urlDecode($this->keyValueParameter()->value()); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -26,107 +26,107 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class ECPrivateKeyJWK extends PrivateKeyJWK |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Parameter names managed by this class. |
|
| 31 | - * |
|
| 32 | - * @internal |
|
| 33 | - * |
|
| 34 | - * @var string[] |
|
| 35 | - */ |
|
| 36 | - const MANAGED_PARAMS = array( |
|
| 37 | - /* @formatter:off */ |
|
| 38 | - JWKParameter::PARAM_KEY_TYPE, |
|
| 39 | - JWKParameter::PARAM_CURVE, |
|
| 40 | - JWKParameter::PARAM_X_COORDINATE, |
|
| 41 | - JWKParameter::PARAM_ECC_PRIVATE_KEY |
|
| 42 | - /* @formatter:on */ |
|
| 43 | - ); |
|
| 29 | + /** |
|
| 30 | + * Parameter names managed by this class. |
|
| 31 | + * |
|
| 32 | + * @internal |
|
| 33 | + * |
|
| 34 | + * @var string[] |
|
| 35 | + */ |
|
| 36 | + const MANAGED_PARAMS = array( |
|
| 37 | + /* @formatter:off */ |
|
| 38 | + JWKParameter::PARAM_KEY_TYPE, |
|
| 39 | + JWKParameter::PARAM_CURVE, |
|
| 40 | + JWKParameter::PARAM_X_COORDINATE, |
|
| 41 | + JWKParameter::PARAM_ECC_PRIVATE_KEY |
|
| 42 | + /* @formatter:on */ |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Constructor. |
|
| 47 | - * |
|
| 48 | - * @param JWKParameter ...$params |
|
| 49 | - * @throws \UnexpectedValueException If missing required parameter |
|
| 50 | - */ |
|
| 51 | - public function __construct(JWKParameter ...$params) |
|
| 52 | - { |
|
| 53 | - parent::__construct(...$params); |
|
| 54 | - foreach (self::MANAGED_PARAMS as $name) { |
|
| 55 | - if (!$this->has($name)) { |
|
| 56 | - throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { |
|
| 60 | - throw new \UnexpectedValueException("Invalid key type."); |
|
| 61 | - } |
|
| 62 | - // cast ECC private key parameter to correct class |
|
| 63 | - $key = JWKParameter::PARAM_ECC_PRIVATE_KEY; |
|
| 64 | - $this->_parameters[$key] = new ECCPrivateKeyParameter( |
|
| 65 | - $this->_parameters[$key]->value()); |
|
| 66 | - } |
|
| 45 | + /** |
|
| 46 | + * Constructor. |
|
| 47 | + * |
|
| 48 | + * @param JWKParameter ...$params |
|
| 49 | + * @throws \UnexpectedValueException If missing required parameter |
|
| 50 | + */ |
|
| 51 | + public function __construct(JWKParameter ...$params) |
|
| 52 | + { |
|
| 53 | + parent::__construct(...$params); |
|
| 54 | + foreach (self::MANAGED_PARAMS as $name) { |
|
| 55 | + if (!$this->has($name)) { |
|
| 56 | + throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { |
|
| 60 | + throw new \UnexpectedValueException("Invalid key type."); |
|
| 61 | + } |
|
| 62 | + // cast ECC private key parameter to correct class |
|
| 63 | + $key = JWKParameter::PARAM_ECC_PRIVATE_KEY; |
|
| 64 | + $this->_parameters[$key] = new ECCPrivateKeyParameter( |
|
| 65 | + $this->_parameters[$key]->value()); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Initialize from ECPrivateKey. |
|
| 70 | - * |
|
| 71 | - * @param ECPrivateKey $pk |
|
| 72 | - * @throws \UnexpectedValueException |
|
| 73 | - * @return self |
|
| 74 | - */ |
|
| 75 | - public static function fromECPrivateKey(ECPrivateKey $pk): self |
|
| 76 | - { |
|
| 77 | - if (!$pk->hasNamedCurve()) { |
|
| 78 | - throw new \UnexpectedValueException("No curve name."); |
|
| 79 | - } |
|
| 80 | - $curve = CurveParameter::fromOID($pk->namedCurve()); |
|
| 81 | - $pubkey = $pk->publicKey(); |
|
| 82 | - list($x, $y) = $pubkey->curvePointOctets(); |
|
| 83 | - $xcoord = XCoordinateParameter::fromString($x); |
|
| 84 | - $ycoord = YCoordinateParameter::fromString($y); |
|
| 85 | - $priv = ECCPrivateKeyParameter::fromString($pk->privateKeyOctets()); |
|
| 86 | - $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC); |
|
| 87 | - return new self($key_type, $curve, $xcoord, $ycoord, $priv); |
|
| 88 | - } |
|
| 68 | + /** |
|
| 69 | + * Initialize from ECPrivateKey. |
|
| 70 | + * |
|
| 71 | + * @param ECPrivateKey $pk |
|
| 72 | + * @throws \UnexpectedValueException |
|
| 73 | + * @return self |
|
| 74 | + */ |
|
| 75 | + public static function fromECPrivateKey(ECPrivateKey $pk): self |
|
| 76 | + { |
|
| 77 | + if (!$pk->hasNamedCurve()) { |
|
| 78 | + throw new \UnexpectedValueException("No curve name."); |
|
| 79 | + } |
|
| 80 | + $curve = CurveParameter::fromOID($pk->namedCurve()); |
|
| 81 | + $pubkey = $pk->publicKey(); |
|
| 82 | + list($x, $y) = $pubkey->curvePointOctets(); |
|
| 83 | + $xcoord = XCoordinateParameter::fromString($x); |
|
| 84 | + $ycoord = YCoordinateParameter::fromString($y); |
|
| 85 | + $priv = ECCPrivateKeyParameter::fromString($pk->privateKeyOctets()); |
|
| 86 | + $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC); |
|
| 87 | + return new self($key_type, $curve, $xcoord, $ycoord, $priv); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Initialize from PEM. |
|
| 92 | - * |
|
| 93 | - * @param PEM $pem |
|
| 94 | - * @return self |
|
| 95 | - */ |
|
| 96 | - public static function fromPEM(PEM $pem): self |
|
| 97 | - { |
|
| 98 | - return self::fromECPrivateKey(ECPrivateKey::fromPEM($pem)); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * Initialize from PEM. |
|
| 92 | + * |
|
| 93 | + * @param PEM $pem |
|
| 94 | + * @return self |
|
| 95 | + */ |
|
| 96 | + public static function fromPEM(PEM $pem): self |
|
| 97 | + { |
|
| 98 | + return self::fromECPrivateKey(ECPrivateKey::fromPEM($pem)); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get the public key component of the EC private key. |
|
| 103 | - * |
|
| 104 | - * @return ECPublicKeyJWK |
|
| 105 | - */ |
|
| 106 | - public function publicKey(): PublicKeyJWK |
|
| 107 | - { |
|
| 108 | - $kty = $this->keyTypeParameter(); |
|
| 109 | - $curve = $this->curveParameter(); |
|
| 110 | - $xcoord = $this->XCoordinateParameter(); |
|
| 111 | - $ycoord = $this->YCoordinateParameter(); |
|
| 112 | - return new ECPublicKeyJWK($kty, $curve, $xcoord, $ycoord); |
|
| 113 | - } |
|
| 101 | + /** |
|
| 102 | + * Get the public key component of the EC private key. |
|
| 103 | + * |
|
| 104 | + * @return ECPublicKeyJWK |
|
| 105 | + */ |
|
| 106 | + public function publicKey(): PublicKeyJWK |
|
| 107 | + { |
|
| 108 | + $kty = $this->keyTypeParameter(); |
|
| 109 | + $curve = $this->curveParameter(); |
|
| 110 | + $xcoord = $this->XCoordinateParameter(); |
|
| 111 | + $ycoord = $this->YCoordinateParameter(); |
|
| 112 | + return new ECPublicKeyJWK($kty, $curve, $xcoord, $ycoord); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Convert EC private key to PEM. |
|
| 117 | - * |
|
| 118 | - * @return PEM |
|
| 119 | - */ |
|
| 120 | - public function toPEM(): PEM |
|
| 121 | - { |
|
| 122 | - $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value()); |
|
| 123 | - $x = ECConversion::octetsToNumber( |
|
| 124 | - $this->XCoordinateParameter()->coordinateOctets()); |
|
| 125 | - $y = ECConversion::octetsToNumber( |
|
| 126 | - $this->YCoordinateParameter()->coordinateOctets()); |
|
| 127 | - $pubkey = ECPublicKey::fromCoordinates($x, $y, $curve_oid); |
|
| 128 | - $priv = $this->ECCPrivateKeyParameter()->privateKeyOctets(); |
|
| 129 | - $ec = new ECPrivateKey($priv, $curve_oid, $pubkey->ECPoint()); |
|
| 130 | - return $ec->privateKeyInfo()->toPEM(); |
|
| 131 | - } |
|
| 115 | + /** |
|
| 116 | + * Convert EC private key to PEM. |
|
| 117 | + * |
|
| 118 | + * @return PEM |
|
| 119 | + */ |
|
| 120 | + public function toPEM(): PEM |
|
| 121 | + { |
|
| 122 | + $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value()); |
|
| 123 | + $x = ECConversion::octetsToNumber( |
|
| 124 | + $this->XCoordinateParameter()->coordinateOctets()); |
|
| 125 | + $y = ECConversion::octetsToNumber( |
|
| 126 | + $this->YCoordinateParameter()->coordinateOctets()); |
|
| 127 | + $pubkey = ECPublicKey::fromCoordinates($x, $y, $curve_oid); |
|
| 128 | + $priv = $this->ECCPrivateKeyParameter()->privateKeyOctets(); |
|
| 129 | + $ec = new ECPrivateKey($priv, $curve_oid, $pubkey->ECPoint()); |
|
| 130 | + return $ec->privateKeyInfo()->toPEM(); |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -23,82 +23,82 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class ECPublicKeyJWK extends PublicKeyJWK |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Parameter names managed by this class. |
|
| 28 | - * |
|
| 29 | - * @var string[] |
|
| 30 | - */ |
|
| 31 | - const MANAGED_PARAMS = array( |
|
| 32 | - /* @formatter:off */ |
|
| 33 | - JWKParameter::PARAM_KEY_TYPE, |
|
| 34 | - JWKParameter::PARAM_CURVE, |
|
| 35 | - JWKParameter::PARAM_X_COORDINATE |
|
| 36 | - /* @formatter:on */ |
|
| 37 | - ); |
|
| 26 | + /** |
|
| 27 | + * Parameter names managed by this class. |
|
| 28 | + * |
|
| 29 | + * @var string[] |
|
| 30 | + */ |
|
| 31 | + const MANAGED_PARAMS = array( |
|
| 32 | + /* @formatter:off */ |
|
| 33 | + JWKParameter::PARAM_KEY_TYPE, |
|
| 34 | + JWKParameter::PARAM_CURVE, |
|
| 35 | + JWKParameter::PARAM_X_COORDINATE |
|
| 36 | + /* @formatter:on */ |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Constructor. |
|
| 41 | - * |
|
| 42 | - * @param JWKParameter ...$params |
|
| 43 | - * @throws \UnexpectedValueException If missing required parameter |
|
| 44 | - */ |
|
| 45 | - public function __construct(JWKParameter ...$params) |
|
| 46 | - { |
|
| 47 | - parent::__construct(...$params); |
|
| 48 | - foreach (self::MANAGED_PARAMS as $name) { |
|
| 49 | - if (!$this->has($name)) { |
|
| 50 | - throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { |
|
| 54 | - throw new \UnexpectedValueException("Invalid key type."); |
|
| 55 | - } |
|
| 56 | - } |
|
| 39 | + /** |
|
| 40 | + * Constructor. |
|
| 41 | + * |
|
| 42 | + * @param JWKParameter ...$params |
|
| 43 | + * @throws \UnexpectedValueException If missing required parameter |
|
| 44 | + */ |
|
| 45 | + public function __construct(JWKParameter ...$params) |
|
| 46 | + { |
|
| 47 | + parent::__construct(...$params); |
|
| 48 | + foreach (self::MANAGED_PARAMS as $name) { |
|
| 49 | + if (!$this->has($name)) { |
|
| 50 | + throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { |
|
| 54 | + throw new \UnexpectedValueException("Invalid key type."); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Initialize from ECPublicKey. |
|
| 60 | - * |
|
| 61 | - * @param ECPublicKey $pk |
|
| 62 | - * @throws \UnexpectedValueException |
|
| 63 | - * @return self |
|
| 64 | - */ |
|
| 65 | - public static function fromECPublicKey(ECPublicKey $pk): self |
|
| 66 | - { |
|
| 67 | - if (!$pk->hasNamedCurve()) { |
|
| 68 | - throw new \UnexpectedValueException("No curve name."); |
|
| 69 | - } |
|
| 70 | - $curve = CurveParameter::fromOID($pk->namedCurve()); |
|
| 71 | - list($x, $y) = $pk->curvePointOctets(); |
|
| 72 | - $xcoord = XCoordinateParameter::fromString($x); |
|
| 73 | - $ycoord = YCoordinateParameter::fromString($y); |
|
| 74 | - $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC); |
|
| 75 | - return new self($key_type, $curve, $xcoord, $ycoord); |
|
| 76 | - } |
|
| 58 | + /** |
|
| 59 | + * Initialize from ECPublicKey. |
|
| 60 | + * |
|
| 61 | + * @param ECPublicKey $pk |
|
| 62 | + * @throws \UnexpectedValueException |
|
| 63 | + * @return self |
|
| 64 | + */ |
|
| 65 | + public static function fromECPublicKey(ECPublicKey $pk): self |
|
| 66 | + { |
|
| 67 | + if (!$pk->hasNamedCurve()) { |
|
| 68 | + throw new \UnexpectedValueException("No curve name."); |
|
| 69 | + } |
|
| 70 | + $curve = CurveParameter::fromOID($pk->namedCurve()); |
|
| 71 | + list($x, $y) = $pk->curvePointOctets(); |
|
| 72 | + $xcoord = XCoordinateParameter::fromString($x); |
|
| 73 | + $ycoord = YCoordinateParameter::fromString($y); |
|
| 74 | + $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC); |
|
| 75 | + return new self($key_type, $curve, $xcoord, $ycoord); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Initialize from PEM. |
|
| 80 | - * |
|
| 81 | - * @param PEM $pem |
|
| 82 | - * @return self |
|
| 83 | - */ |
|
| 84 | - public static function fromPEM(PEM $pem): self |
|
| 85 | - { |
|
| 86 | - return self::fromECPublicKey(ECPublicKey::fromPEM($pem)); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * Initialize from PEM. |
|
| 80 | + * |
|
| 81 | + * @param PEM $pem |
|
| 82 | + * @return self |
|
| 83 | + */ |
|
| 84 | + public static function fromPEM(PEM $pem): self |
|
| 85 | + { |
|
| 86 | + return self::fromECPublicKey(ECPublicKey::fromPEM($pem)); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Convert EC public key to PEM. |
|
| 91 | - * |
|
| 92 | - * @return PEM |
|
| 93 | - */ |
|
| 94 | - public function toPEM(): PEM |
|
| 95 | - { |
|
| 96 | - $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value()); |
|
| 97 | - $x = ECConversion::octetsToNumber( |
|
| 98 | - $this->XCoordinateParameter()->coordinateOctets()); |
|
| 99 | - $y = ECConversion::octetsToNumber( |
|
| 100 | - $this->YCoordinateParameter()->coordinateOctets()); |
|
| 101 | - $ec = ECPublicKey::fromCoordinates($x, $y, $curve_oid); |
|
| 102 | - return $ec->publicKeyInfo()->toPEM(); |
|
| 103 | - } |
|
| 89 | + /** |
|
| 90 | + * Convert EC public key to PEM. |
|
| 91 | + * |
|
| 92 | + * @return PEM |
|
| 93 | + */ |
|
| 94 | + public function toPEM(): PEM |
|
| 95 | + { |
|
| 96 | + $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value()); |
|
| 97 | + $x = ECConversion::octetsToNumber( |
|
| 98 | + $this->XCoordinateParameter()->coordinateOctets()); |
|
| 99 | + $y = ECConversion::octetsToNumber( |
|
| 100 | + $this->YCoordinateParameter()->coordinateOctets()); |
|
| 101 | + $ec = ECPublicKey::fromCoordinates($x, $y, $curve_oid); |
|
| 102 | + return $ec->publicKeyInfo()->toPEM(); |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ModulusParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $n Modulus in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $n) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($n); |
|
| 26 | - parent::__construct(self::PARAM_MODULUS, $n); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $n Modulus in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $n) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($n); |
|
| 26 | + parent::__construct(self::PARAM_MODULUS, $n); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class X509URLParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $uri |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $uri) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_X509_URL, $uri); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $uri |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $uri) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_X509_URL, $uri); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -13,30 +13,30 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyTypeParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Octet sequence key type. |
|
| 20 | - */ |
|
| 21 | - const TYPE_OCT = "oct"; |
|
| 18 | + /** |
|
| 19 | + * Octet sequence key type. |
|
| 20 | + */ |
|
| 21 | + const TYPE_OCT = "oct"; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * RSA key type. |
|
| 25 | - */ |
|
| 26 | - const TYPE_RSA = "RSA"; |
|
| 23 | + /** |
|
| 24 | + * RSA key type. |
|
| 25 | + */ |
|
| 26 | + const TYPE_RSA = "RSA"; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Elliptic curve key type. |
|
| 30 | - */ |
|
| 31 | - const TYPE_EC = "EC"; |
|
| 28 | + /** |
|
| 29 | + * Elliptic curve key type. |
|
| 30 | + */ |
|
| 31 | + const TYPE_EC = "EC"; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $type Key type |
|
| 37 | - */ |
|
| 38 | - public function __construct(string $type) |
|
| 39 | - { |
|
| 40 | - parent::__construct(self::PARAM_KEY_TYPE, $type); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $type Key type |
|
| 37 | + */ |
|
| 38 | + public function __construct(string $type) |
|
| 39 | + { |
|
| 40 | + parent::__construct(self::PARAM_KEY_TYPE, $type); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SecondPrimeFactorParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $q Second prime factor in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $q) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($q); |
|
| 26 | - parent::__construct(self::PARAM_SECOND_PRIME_FACTOR, $q); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $q Second prime factor in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $q) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($q); |
|
| 26 | + parent::__construct(self::PARAM_SECOND_PRIME_FACTOR, $q); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyIDParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $id Key ID |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $id) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_KEY_ID, $id); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $id Key ID |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $id) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_KEY_ID, $id); |
|
| 26 | + } |
|
| 27 | 27 | } |