GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch php72 (880eb0)
by Joni
05:58
created
lib/JWX/JWK/Parameter/FirstCRTCoefficientParameter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Parameter;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/Parameter/SecondFactorCRTExponentParameter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Parameter;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/Parameter/KeyValueParameter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Parameter;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/Parameter/OtherPrimesInfoParameter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Parameter;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/TypedJWK.php 2 patches
Indentation   +590 added lines, -590 removed lines patch added patch discarded remove patch
@@ -11,594 +11,594 @@
 block discarded – undo
11 11
  */
12 12
 trait TypedJWK
13 13
 {
14
-    /**
15
-     * Whether parameters are present.
16
-     *
17
-     * @param string ...$names Parameter names
18
-     *
19
-     * @return bool
20
-     */
21
-    abstract public function has(string ...$names): bool;
22
-
23
-    /**
24
-     * Get a parameter.
25
-     *
26
-     * @param string $name Parameter name
27
-     *
28
-     * @return JWKParameter
29
-     */
30
-    abstract public function get(string $name): JWKParameter;
31
-
32
-    /**
33
-     * Check whether the algorithm parameter is present.
34
-     *
35
-     * @return bool
36
-     */
37
-    public function hasAlgorithmParameter(): bool
38
-    {
39
-        return $this->has(Parameter\JWKParameter::P_ALG);
40
-    }
41
-
42
-    /**
43
-     * Get the algorithm parameter.
44
-     *
45
-     * @throws \UnexpectedValueException If the parameter has a wrong class
46
-     * @throws \LogicException           If the parameter is not present
47
-     *
48
-     * @return Parameter\AlgorithmParameter
49
-     */
50
-    public function algorithmParameter(): Parameter\AlgorithmParameter
51
-    {
52
-        return self::_checkType($this->get(Parameter\JWKParameter::P_ALG),
53
-            Parameter\AlgorithmParameter::class);
54
-    }
55
-
56
-    /**
57
-     * Check whether the curve parameter is present.
58
-     *
59
-     * @return bool
60
-     */
61
-    public function hasCurveParameter(): bool
62
-    {
63
-        return $this->has(Parameter\JWKParameter::P_CRV);
64
-    }
65
-
66
-    /**
67
-     * Get the curve parameter.
68
-     *
69
-     * @throws \UnexpectedValueException If the parameter has a wrong class
70
-     * @throws \LogicException           If the parameter is not present
71
-     *
72
-     * @return Parameter\CurveParameter
73
-     */
74
-    public function curveParameter(): Parameter\CurveParameter
75
-    {
76
-        return self::_checkType($this->get(Parameter\JWKParameter::P_CRV),
77
-            Parameter\CurveParameter::class);
78
-    }
79
-
80
-    /**
81
-     * Check whether the ECC private key parameter is present.
82
-     *
83
-     * @return bool
84
-     */
85
-    public function hasECCPrivateKeyParameter(): bool
86
-    {
87
-        return $this->has(Parameter\JWKParameter::P_ECC_D);
88
-    }
89
-
90
-    /**
91
-     * Get the ECC private key parameter.
92
-     *
93
-     * @throws \UnexpectedValueException If the parameter has a wrong class
94
-     * @throws \LogicException           If the parameter is not present
95
-     *
96
-     * @return Parameter\ECCPrivateKeyParameter
97
-     */
98
-    public function ECCPrivateKeyParameter(): Parameter\ECCPrivateKeyParameter
99
-    {
100
-        return self::_checkType($this->get(Parameter\JWKParameter::P_ECC_D),
101
-            Parameter\ECCPrivateKeyParameter::class);
102
-    }
103
-
104
-    /**
105
-     * Check whether the exponent parameter is present.
106
-     *
107
-     * @return bool
108
-     */
109
-    public function hasExponentParameter(): bool
110
-    {
111
-        return $this->has(Parameter\JWKParameter::P_E);
112
-    }
113
-
114
-    /**
115
-     * Get the exponent parameter.
116
-     *
117
-     * @throws \UnexpectedValueException If the parameter has a wrong class
118
-     * @throws \LogicException           If the parameter is not present
119
-     *
120
-     * @return Parameter\ExponentParameter
121
-     */
122
-    public function exponentParameter(): Parameter\ExponentParameter
123
-    {
124
-        return self::_checkType($this->get(Parameter\JWKParameter::P_E),
125
-            Parameter\ExponentParameter::class);
126
-    }
127
-
128
-    /**
129
-     * Check whether the first CRT coefficient parameter is present.
130
-     *
131
-     * @return bool
132
-     */
133
-    public function hasFirstCRTCoefficientParameter(): bool
134
-    {
135
-        return $this->has(Parameter\JWKParameter::P_QI);
136
-    }
137
-
138
-    /**
139
-     * Get the first CRT coefficient parameter.
140
-     *
141
-     * @throws \UnexpectedValueException If the parameter has a wrong class
142
-     * @throws \LogicException           If the parameter is not present
143
-     *
144
-     * @return Parameter\FirstCRTCoefficientParameter
145
-     */
146
-    public function firstCRTCoefficientParameter(): Parameter\FirstCRTCoefficientParameter
147
-    {
148
-        return self::_checkType($this->get(Parameter\JWKParameter::P_QI),
149
-            Parameter\FirstCRTCoefficientParameter::class);
150
-    }
151
-
152
-    /**
153
-     * Check whether the first factor CRT exponent parameter is present.
154
-     *
155
-     * @return bool
156
-     */
157
-    public function hasFirstFactorCRTExponentParameter(): bool
158
-    {
159
-        return $this->has(Parameter\JWKParameter::P_DP);
160
-    }
161
-
162
-    /**
163
-     * Get the first factor CRT exponent parameter.
164
-     *
165
-     * @throws \UnexpectedValueException If the parameter has a wrong class
166
-     * @throws \LogicException           If the parameter is not present
167
-     *
168
-     * @return Parameter\FirstFactorCRTExponentParameter
169
-     */
170
-    public function firstFactorCRTExponentParameter(): Parameter\FirstFactorCRTExponentParameter
171
-    {
172
-        return self::_checkType($this->get(Parameter\JWKParameter::P_DP),
173
-            Parameter\FirstFactorCRTExponentParameter::class);
174
-    }
175
-
176
-    /**
177
-     * Check whether the first prime factor parameter is present.
178
-     *
179
-     * @return bool
180
-     */
181
-    public function hasFirstPrimeFactorParameter(): bool
182
-    {
183
-        return $this->has(Parameter\JWKParameter::P_P);
184
-    }
185
-
186
-    /**
187
-     * Get the first prime factor parameter.
188
-     *
189
-     * @throws \UnexpectedValueException If the parameter has a wrong class
190
-     * @throws \LogicException           If the parameter is not present
191
-     *
192
-     * @return Parameter\FirstPrimeFactorParameter
193
-     */
194
-    public function firstPrimeFactorParameter(): Parameter\FirstPrimeFactorParameter
195
-    {
196
-        return self::_checkType($this->get(Parameter\JWKParameter::P_P),
197
-            Parameter\FirstPrimeFactorParameter::class);
198
-    }
199
-
200
-    /**
201
-     * Check whether the key ID parameter is present.
202
-     *
203
-     * @return bool
204
-     */
205
-    public function hasKeyIDParameter(): bool
206
-    {
207
-        return $this->has(Parameter\JWKParameter::P_KID);
208
-    }
209
-
210
-    /**
211
-     * Get the key ID parameter.
212
-     *
213
-     * @throws \UnexpectedValueException If the parameter has a wrong class
214
-     * @throws \LogicException           If the parameter is not present
215
-     *
216
-     * @return Parameter\KeyIDParameter
217
-     */
218
-    public function keyIDParameter(): Parameter\KeyIDParameter
219
-    {
220
-        return self::_checkType($this->get(Parameter\JWKParameter::P_KID),
221
-            Parameter\KeyIDParameter::class);
222
-    }
223
-
224
-    /**
225
-     * Check whether the key operations parameter is present.
226
-     *
227
-     * @return bool
228
-     */
229
-    public function hasKeyOperationsParameter(): bool
230
-    {
231
-        return $this->has(Parameter\JWKParameter::P_KEY_OPS);
232
-    }
233
-
234
-    /**
235
-     * Get the key operations parameter.
236
-     *
237
-     * @throws \UnexpectedValueException If the parameter has a wrong class
238
-     * @throws \LogicException           If the parameter is not present
239
-     *
240
-     * @return Parameter\KeyOperationsParameter
241
-     */
242
-    public function keyOperationsParameter(): Parameter\KeyOperationsParameter
243
-    {
244
-        return self::_checkType($this->get(Parameter\JWKParameter::P_KEY_OPS),
245
-            Parameter\KeyOperationsParameter::class);
246
-    }
247
-
248
-    /**
249
-     * Check whether the key type parameter is present.
250
-     *
251
-     * @return bool
252
-     */
253
-    public function hasKeyTypeParameter(): bool
254
-    {
255
-        return $this->has(Parameter\JWKParameter::P_KTY);
256
-    }
257
-
258
-    /**
259
-     * Get the key type parameter.
260
-     *
261
-     * @throws \UnexpectedValueException If the parameter has a wrong class
262
-     * @throws \LogicException           If the parameter is not present
263
-     *
264
-     * @return Parameter\KeyTypeParameter
265
-     */
266
-    public function keyTypeParameter(): Parameter\KeyTypeParameter
267
-    {
268
-        return self::_checkType($this->get(Parameter\JWKParameter::P_KTY),
269
-            Parameter\KeyTypeParameter::class);
270
-    }
271
-
272
-    /**
273
-     * Check whether the key value parameter is present.
274
-     *
275
-     * @return bool
276
-     */
277
-    public function hasKeyValueParameter(): bool
278
-    {
279
-        return $this->has(Parameter\JWKParameter::P_K);
280
-    }
281
-
282
-    /**
283
-     * Get the key value parameter.
284
-     *
285
-     * @throws \UnexpectedValueException If the parameter has a wrong class
286
-     * @throws \LogicException           If the parameter is not present
287
-     *
288
-     * @return Parameter\KeyValueParameter
289
-     */
290
-    public function keyValueParameter(): Parameter\KeyValueParameter
291
-    {
292
-        return self::_checkType($this->get(Parameter\JWKParameter::P_K),
293
-            Parameter\KeyValueParameter::class);
294
-    }
295
-
296
-    /**
297
-     * Check whether the modulus parameter is present.
298
-     *
299
-     * @return bool
300
-     */
301
-    public function hasModulusParameter(): bool
302
-    {
303
-        return $this->has(Parameter\JWKParameter::P_N);
304
-    }
305
-
306
-    /**
307
-     * Get the modulus parameter.
308
-     *
309
-     * @throws \UnexpectedValueException If the parameter has a wrong class
310
-     * @throws \LogicException           If the parameter is not present
311
-     *
312
-     * @return Parameter\ModulusParameter
313
-     */
314
-    public function modulusParameter(): Parameter\ModulusParameter
315
-    {
316
-        return self::_checkType($this->get(Parameter\JWKParameter::P_N),
317
-            Parameter\ModulusParameter::class);
318
-    }
319
-
320
-    /**
321
-     * Check whether the other primes info parameter is present.
322
-     *
323
-     * @return bool
324
-     */
325
-    public function hasOtherPrimesInfoParameter(): bool
326
-    {
327
-        return $this->has(Parameter\JWKParameter::P_OTH);
328
-    }
329
-
330
-    /**
331
-     * Get the other primes info parameter.
332
-     *
333
-     * @throws \UnexpectedValueException If the parameter has a wrong class
334
-     * @throws \LogicException           If the parameter is not present
335
-     *
336
-     * @return Parameter\OtherPrimesInfoParameter
337
-     */
338
-    public function otherPrimesInfoParameter(): Parameter\OtherPrimesInfoParameter
339
-    {
340
-        return self::_checkType($this->get(Parameter\JWKParameter::P_OTH),
341
-            Parameter\OtherPrimesInfoParameter::class);
342
-    }
343
-
344
-    /**
345
-     * Check whether the private exponent parameter is present.
346
-     *
347
-     * @return bool
348
-     */
349
-    public function hasPrivateExponentParameter(): bool
350
-    {
351
-        return $this->has(Parameter\JWKParameter::P_RSA_D);
352
-    }
353
-
354
-    /**
355
-     * Get the private exponent parameter.
356
-     *
357
-     * @throws \UnexpectedValueException If the parameter has a wrong class
358
-     * @throws \LogicException           If the parameter is not present
359
-     *
360
-     * @return Parameter\PrivateExponentParameter
361
-     */
362
-    public function privateExponentParameter(): Parameter\PrivateExponentParameter
363
-    {
364
-        return self::_checkType($this->get(Parameter\JWKParameter::P_RSA_D),
365
-            Parameter\PrivateExponentParameter::class);
366
-    }
367
-
368
-    /**
369
-     * Check whether the public key use parameter is present.
370
-     *
371
-     * @return bool
372
-     */
373
-    public function hasPublicKeyUseParameter(): bool
374
-    {
375
-        return $this->has(Parameter\JWKParameter::P_USE);
376
-    }
377
-
378
-    /**
379
-     * Get the public key use parameter.
380
-     *
381
-     * @throws \UnexpectedValueException If the parameter has a wrong class
382
-     * @throws \LogicException           If the parameter is not present
383
-     *
384
-     * @return Parameter\PublicKeyUseParameter
385
-     */
386
-    public function publicKeyUseParameter(): Parameter\PublicKeyUseParameter
387
-    {
388
-        return self::_checkType($this->get(Parameter\JWKParameter::P_USE),
389
-            Parameter\PublicKeyUseParameter::class);
390
-    }
391
-
392
-    /**
393
-     * Check whether the second factor CRT exponent parameter is present.
394
-     *
395
-     * @return bool
396
-     */
397
-    public function hasSecondFactorCRTExponentParameter(): bool
398
-    {
399
-        return $this->has(Parameter\JWKParameter::P_DQ);
400
-    }
401
-
402
-    /**
403
-     * Get the second factor CRT exponent parameter.
404
-     *
405
-     * @throws \UnexpectedValueException If the parameter has a wrong class
406
-     * @throws \LogicException           If the parameter is not present
407
-     *
408
-     * @return Parameter\SecondFactorCRTExponentParameter
409
-     */
410
-    public function secondFactorCRTExponentParameter(): Parameter\SecondFactorCRTExponentParameter
411
-    {
412
-        return self::_checkType($this->get(Parameter\JWKParameter::P_DQ),
413
-            Parameter\SecondFactorCRTExponentParameter::class);
414
-    }
415
-
416
-    /**
417
-     * Check whether the second prime factor parameter is present.
418
-     *
419
-     * @return bool
420
-     */
421
-    public function hasSecondPrimeFactorParameter(): bool
422
-    {
423
-        return $this->has(Parameter\JWKParameter::P_Q);
424
-    }
425
-
426
-    /**
427
-     * Get the second prime factor parameter.
428
-     *
429
-     * @throws \UnexpectedValueException If the parameter has a wrong class
430
-     * @throws \LogicException           If the parameter is not present
431
-     *
432
-     * @return Parameter\SecondPrimeFactorParameter
433
-     */
434
-    public function secondPrimeFactorParameter(): Parameter\SecondPrimeFactorParameter
435
-    {
436
-        return self::_checkType($this->get(Parameter\JWKParameter::P_Q),
437
-            Parameter\SecondPrimeFactorParameter::class);
438
-    }
439
-
440
-    /**
441
-     * Check whether the X.509 certificate chain parameter is present.
442
-     *
443
-     * @return bool
444
-     */
445
-    public function hasX509CertificateChainParameter(): bool
446
-    {
447
-        return $this->has(Parameter\JWKParameter::P_X5C);
448
-    }
449
-
450
-    /**
451
-     * Get the X.509 certificate chain parameter.
452
-     *
453
-     * @throws \UnexpectedValueException If the parameter has a wrong class
454
-     * @throws \LogicException           If the parameter is not present
455
-     *
456
-     * @return Parameter\X509CertificateChainParameter
457
-     */
458
-    public function X509CertificateChainParameter(): Parameter\X509CertificateChainParameter
459
-    {
460
-        return self::_checkType($this->get(Parameter\JWKParameter::P_X5C),
461
-            Parameter\X509CertificateChainParameter::class);
462
-    }
463
-
464
-    /**
465
-     * Check whether the X.509 certificate SHA-1 thumbprint parameter is
466
-     * present.
467
-     *
468
-     * @return bool
469
-     */
470
-    public function hasX509CertificateSHA1ThumbprintParameter(): bool
471
-    {
472
-        return $this->has(Parameter\JWKParameter::P_X5T);
473
-    }
474
-
475
-    /**
476
-     * Get the X.509 certificate SHA-1 thumbprint parameter.
477
-     *
478
-     * @throws \UnexpectedValueException If the parameter has a wrong class
479
-     * @throws \LogicException           If the parameter is not present
480
-     *
481
-     * @return Parameter\X509CertificateSHA1ThumbprintParameter
482
-     */
483
-    public function X509CertificateSHA1ThumbprintParameter(): Parameter\X509CertificateSHA1ThumbprintParameter
484
-    {
485
-        return self::_checkType($this->get(Parameter\JWKParameter::P_X5T),
486
-            Parameter\X509CertificateSHA1ThumbprintParameter::class);
487
-    }
488
-
489
-    /**
490
-     * Check whether the X.509 certificate SHA-256 thumbprint parameter is
491
-     * present.
492
-     *
493
-     * @return bool
494
-     */
495
-    public function hasX509CertificateSHA256ThumbprintParameter(): bool
496
-    {
497
-        return $this->has(Parameter\JWKParameter::P_X5TS256);
498
-    }
499
-
500
-    /**
501
-     * Get the X.509 certificate SHA-256 thumbprint parameter.
502
-     *
503
-     * @throws \UnexpectedValueException If the parameter has a wrong class
504
-     * @throws \LogicException           If the parameter is not present
505
-     *
506
-     * @return Parameter\X509CertificateSHA256ThumbprintParameter
507
-     */
508
-    public function X509CertificateSHA256ThumbprintParameter(): Parameter\X509CertificateSHA256ThumbprintParameter
509
-    {
510
-        return self::_checkType($this->get(Parameter\JWKParameter::P_X5TS256),
511
-            Parameter\X509CertificateSHA256ThumbprintParameter::class);
512
-    }
513
-
514
-    /**
515
-     * Check whether the X.509 URL parameter is present.
516
-     *
517
-     * @return bool
518
-     */
519
-    public function hasX509URLParameter(): bool
520
-    {
521
-        return $this->has(Parameter\JWKParameter::P_X5U);
522
-    }
523
-
524
-    /**
525
-     * Get the X.509 URL parameter.
526
-     *
527
-     * @throws \UnexpectedValueException If the parameter has a wrong class
528
-     * @throws \LogicException           If the parameter is not present
529
-     *
530
-     * @return Parameter\X509URLParameter
531
-     */
532
-    public function X509URLParameter(): Parameter\X509URLParameter
533
-    {
534
-        return self::_checkType($this->get(Parameter\JWKParameter::P_X5U),
535
-            Parameter\X509URLParameter::class);
536
-    }
537
-
538
-    /**
539
-     * Check whether the X coordinate parameter is present.
540
-     *
541
-     * @return bool
542
-     */
543
-    public function hasXCoordinateParameter(): bool
544
-    {
545
-        return $this->has(Parameter\JWKParameter::P_X);
546
-    }
547
-
548
-    /**
549
-     * Get the X coordinate parameter.
550
-     *
551
-     * @throws \UnexpectedValueException If the parameter has a wrong class
552
-     * @throws \LogicException           If the parameter is not present
553
-     *
554
-     * @return Parameter\XCoordinateParameter
555
-     */
556
-    public function XCoordinateParameter(): Parameter\XCoordinateParameter
557
-    {
558
-        return self::_checkType($this->get(Parameter\JWKParameter::P_X),
559
-            Parameter\XCoordinateParameter::class);
560
-    }
561
-
562
-    /**
563
-     * Check whether the Y coordinate parameter is present.
564
-     *
565
-     * @return bool
566
-     */
567
-    public function hasYCoordinateParameter(): bool
568
-    {
569
-        return $this->has(Parameter\JWKParameter::P_Y);
570
-    }
571
-
572
-    /**
573
-     * Get the Y coordinate parameter.
574
-     *
575
-     * @throws \UnexpectedValueException If the parameter has a wrong class
576
-     * @throws \LogicException           If the parameter is not present
577
-     *
578
-     * @return Parameter\YCoordinateParameter
579
-     */
580
-    public function YCoordinateParameter(): Parameter\YCoordinateParameter
581
-    {
582
-        return self::_checkType($this->get(Parameter\JWKParameter::P_Y),
583
-            Parameter\YCoordinateParameter::class);
584
-    }
585
-
586
-    /**
587
-     * Check that the parameter is an instance of the given class.
588
-     *
589
-     * @param Parameter\JWKParameter $param Parameter
590
-     * @param string                 $cls   Class name
591
-     *
592
-     * @throws \UnexpectedValueException
593
-     *
594
-     * @return Parameter\JWKParameter
595
-     */
596
-    private static function _checkType(Parameter\JWKParameter $param, string $cls): Parameter\JWKParameter
597
-    {
598
-        if (!$param instanceof $cls) {
599
-            throw new \UnexpectedValueException(
600
-                "{$cls} expected, got " . get_class($param));
601
-        }
602
-        return $param;
603
-    }
14
+	/**
15
+	 * Whether parameters are present.
16
+	 *
17
+	 * @param string ...$names Parameter names
18
+	 *
19
+	 * @return bool
20
+	 */
21
+	abstract public function has(string ...$names): bool;
22
+
23
+	/**
24
+	 * Get a parameter.
25
+	 *
26
+	 * @param string $name Parameter name
27
+	 *
28
+	 * @return JWKParameter
29
+	 */
30
+	abstract public function get(string $name): JWKParameter;
31
+
32
+	/**
33
+	 * Check whether the algorithm parameter is present.
34
+	 *
35
+	 * @return bool
36
+	 */
37
+	public function hasAlgorithmParameter(): bool
38
+	{
39
+		return $this->has(Parameter\JWKParameter::P_ALG);
40
+	}
41
+
42
+	/**
43
+	 * Get the algorithm parameter.
44
+	 *
45
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
46
+	 * @throws \LogicException           If the parameter is not present
47
+	 *
48
+	 * @return Parameter\AlgorithmParameter
49
+	 */
50
+	public function algorithmParameter(): Parameter\AlgorithmParameter
51
+	{
52
+		return self::_checkType($this->get(Parameter\JWKParameter::P_ALG),
53
+			Parameter\AlgorithmParameter::class);
54
+	}
55
+
56
+	/**
57
+	 * Check whether the curve parameter is present.
58
+	 *
59
+	 * @return bool
60
+	 */
61
+	public function hasCurveParameter(): bool
62
+	{
63
+		return $this->has(Parameter\JWKParameter::P_CRV);
64
+	}
65
+
66
+	/**
67
+	 * Get the curve parameter.
68
+	 *
69
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
70
+	 * @throws \LogicException           If the parameter is not present
71
+	 *
72
+	 * @return Parameter\CurveParameter
73
+	 */
74
+	public function curveParameter(): Parameter\CurveParameter
75
+	{
76
+		return self::_checkType($this->get(Parameter\JWKParameter::P_CRV),
77
+			Parameter\CurveParameter::class);
78
+	}
79
+
80
+	/**
81
+	 * Check whether the ECC private key parameter is present.
82
+	 *
83
+	 * @return bool
84
+	 */
85
+	public function hasECCPrivateKeyParameter(): bool
86
+	{
87
+		return $this->has(Parameter\JWKParameter::P_ECC_D);
88
+	}
89
+
90
+	/**
91
+	 * Get the ECC private key parameter.
92
+	 *
93
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
94
+	 * @throws \LogicException           If the parameter is not present
95
+	 *
96
+	 * @return Parameter\ECCPrivateKeyParameter
97
+	 */
98
+	public function ECCPrivateKeyParameter(): Parameter\ECCPrivateKeyParameter
99
+	{
100
+		return self::_checkType($this->get(Parameter\JWKParameter::P_ECC_D),
101
+			Parameter\ECCPrivateKeyParameter::class);
102
+	}
103
+
104
+	/**
105
+	 * Check whether the exponent parameter is present.
106
+	 *
107
+	 * @return bool
108
+	 */
109
+	public function hasExponentParameter(): bool
110
+	{
111
+		return $this->has(Parameter\JWKParameter::P_E);
112
+	}
113
+
114
+	/**
115
+	 * Get the exponent parameter.
116
+	 *
117
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
118
+	 * @throws \LogicException           If the parameter is not present
119
+	 *
120
+	 * @return Parameter\ExponentParameter
121
+	 */
122
+	public function exponentParameter(): Parameter\ExponentParameter
123
+	{
124
+		return self::_checkType($this->get(Parameter\JWKParameter::P_E),
125
+			Parameter\ExponentParameter::class);
126
+	}
127
+
128
+	/**
129
+	 * Check whether the first CRT coefficient parameter is present.
130
+	 *
131
+	 * @return bool
132
+	 */
133
+	public function hasFirstCRTCoefficientParameter(): bool
134
+	{
135
+		return $this->has(Parameter\JWKParameter::P_QI);
136
+	}
137
+
138
+	/**
139
+	 * Get the first CRT coefficient parameter.
140
+	 *
141
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
142
+	 * @throws \LogicException           If the parameter is not present
143
+	 *
144
+	 * @return Parameter\FirstCRTCoefficientParameter
145
+	 */
146
+	public function firstCRTCoefficientParameter(): Parameter\FirstCRTCoefficientParameter
147
+	{
148
+		return self::_checkType($this->get(Parameter\JWKParameter::P_QI),
149
+			Parameter\FirstCRTCoefficientParameter::class);
150
+	}
151
+
152
+	/**
153
+	 * Check whether the first factor CRT exponent parameter is present.
154
+	 *
155
+	 * @return bool
156
+	 */
157
+	public function hasFirstFactorCRTExponentParameter(): bool
158
+	{
159
+		return $this->has(Parameter\JWKParameter::P_DP);
160
+	}
161
+
162
+	/**
163
+	 * Get the first factor CRT exponent parameter.
164
+	 *
165
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
166
+	 * @throws \LogicException           If the parameter is not present
167
+	 *
168
+	 * @return Parameter\FirstFactorCRTExponentParameter
169
+	 */
170
+	public function firstFactorCRTExponentParameter(): Parameter\FirstFactorCRTExponentParameter
171
+	{
172
+		return self::_checkType($this->get(Parameter\JWKParameter::P_DP),
173
+			Parameter\FirstFactorCRTExponentParameter::class);
174
+	}
175
+
176
+	/**
177
+	 * Check whether the first prime factor parameter is present.
178
+	 *
179
+	 * @return bool
180
+	 */
181
+	public function hasFirstPrimeFactorParameter(): bool
182
+	{
183
+		return $this->has(Parameter\JWKParameter::P_P);
184
+	}
185
+
186
+	/**
187
+	 * Get the first prime factor parameter.
188
+	 *
189
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
190
+	 * @throws \LogicException           If the parameter is not present
191
+	 *
192
+	 * @return Parameter\FirstPrimeFactorParameter
193
+	 */
194
+	public function firstPrimeFactorParameter(): Parameter\FirstPrimeFactorParameter
195
+	{
196
+		return self::_checkType($this->get(Parameter\JWKParameter::P_P),
197
+			Parameter\FirstPrimeFactorParameter::class);
198
+	}
199
+
200
+	/**
201
+	 * Check whether the key ID parameter is present.
202
+	 *
203
+	 * @return bool
204
+	 */
205
+	public function hasKeyIDParameter(): bool
206
+	{
207
+		return $this->has(Parameter\JWKParameter::P_KID);
208
+	}
209
+
210
+	/**
211
+	 * Get the key ID parameter.
212
+	 *
213
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
214
+	 * @throws \LogicException           If the parameter is not present
215
+	 *
216
+	 * @return Parameter\KeyIDParameter
217
+	 */
218
+	public function keyIDParameter(): Parameter\KeyIDParameter
219
+	{
220
+		return self::_checkType($this->get(Parameter\JWKParameter::P_KID),
221
+			Parameter\KeyIDParameter::class);
222
+	}
223
+
224
+	/**
225
+	 * Check whether the key operations parameter is present.
226
+	 *
227
+	 * @return bool
228
+	 */
229
+	public function hasKeyOperationsParameter(): bool
230
+	{
231
+		return $this->has(Parameter\JWKParameter::P_KEY_OPS);
232
+	}
233
+
234
+	/**
235
+	 * Get the key operations parameter.
236
+	 *
237
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
238
+	 * @throws \LogicException           If the parameter is not present
239
+	 *
240
+	 * @return Parameter\KeyOperationsParameter
241
+	 */
242
+	public function keyOperationsParameter(): Parameter\KeyOperationsParameter
243
+	{
244
+		return self::_checkType($this->get(Parameter\JWKParameter::P_KEY_OPS),
245
+			Parameter\KeyOperationsParameter::class);
246
+	}
247
+
248
+	/**
249
+	 * Check whether the key type parameter is present.
250
+	 *
251
+	 * @return bool
252
+	 */
253
+	public function hasKeyTypeParameter(): bool
254
+	{
255
+		return $this->has(Parameter\JWKParameter::P_KTY);
256
+	}
257
+
258
+	/**
259
+	 * Get the key type parameter.
260
+	 *
261
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
262
+	 * @throws \LogicException           If the parameter is not present
263
+	 *
264
+	 * @return Parameter\KeyTypeParameter
265
+	 */
266
+	public function keyTypeParameter(): Parameter\KeyTypeParameter
267
+	{
268
+		return self::_checkType($this->get(Parameter\JWKParameter::P_KTY),
269
+			Parameter\KeyTypeParameter::class);
270
+	}
271
+
272
+	/**
273
+	 * Check whether the key value parameter is present.
274
+	 *
275
+	 * @return bool
276
+	 */
277
+	public function hasKeyValueParameter(): bool
278
+	{
279
+		return $this->has(Parameter\JWKParameter::P_K);
280
+	}
281
+
282
+	/**
283
+	 * Get the key value parameter.
284
+	 *
285
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
286
+	 * @throws \LogicException           If the parameter is not present
287
+	 *
288
+	 * @return Parameter\KeyValueParameter
289
+	 */
290
+	public function keyValueParameter(): Parameter\KeyValueParameter
291
+	{
292
+		return self::_checkType($this->get(Parameter\JWKParameter::P_K),
293
+			Parameter\KeyValueParameter::class);
294
+	}
295
+
296
+	/**
297
+	 * Check whether the modulus parameter is present.
298
+	 *
299
+	 * @return bool
300
+	 */
301
+	public function hasModulusParameter(): bool
302
+	{
303
+		return $this->has(Parameter\JWKParameter::P_N);
304
+	}
305
+
306
+	/**
307
+	 * Get the modulus parameter.
308
+	 *
309
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
310
+	 * @throws \LogicException           If the parameter is not present
311
+	 *
312
+	 * @return Parameter\ModulusParameter
313
+	 */
314
+	public function modulusParameter(): Parameter\ModulusParameter
315
+	{
316
+		return self::_checkType($this->get(Parameter\JWKParameter::P_N),
317
+			Parameter\ModulusParameter::class);
318
+	}
319
+
320
+	/**
321
+	 * Check whether the other primes info parameter is present.
322
+	 *
323
+	 * @return bool
324
+	 */
325
+	public function hasOtherPrimesInfoParameter(): bool
326
+	{
327
+		return $this->has(Parameter\JWKParameter::P_OTH);
328
+	}
329
+
330
+	/**
331
+	 * Get the other primes info parameter.
332
+	 *
333
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
334
+	 * @throws \LogicException           If the parameter is not present
335
+	 *
336
+	 * @return Parameter\OtherPrimesInfoParameter
337
+	 */
338
+	public function otherPrimesInfoParameter(): Parameter\OtherPrimesInfoParameter
339
+	{
340
+		return self::_checkType($this->get(Parameter\JWKParameter::P_OTH),
341
+			Parameter\OtherPrimesInfoParameter::class);
342
+	}
343
+
344
+	/**
345
+	 * Check whether the private exponent parameter is present.
346
+	 *
347
+	 * @return bool
348
+	 */
349
+	public function hasPrivateExponentParameter(): bool
350
+	{
351
+		return $this->has(Parameter\JWKParameter::P_RSA_D);
352
+	}
353
+
354
+	/**
355
+	 * Get the private exponent parameter.
356
+	 *
357
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
358
+	 * @throws \LogicException           If the parameter is not present
359
+	 *
360
+	 * @return Parameter\PrivateExponentParameter
361
+	 */
362
+	public function privateExponentParameter(): Parameter\PrivateExponentParameter
363
+	{
364
+		return self::_checkType($this->get(Parameter\JWKParameter::P_RSA_D),
365
+			Parameter\PrivateExponentParameter::class);
366
+	}
367
+
368
+	/**
369
+	 * Check whether the public key use parameter is present.
370
+	 *
371
+	 * @return bool
372
+	 */
373
+	public function hasPublicKeyUseParameter(): bool
374
+	{
375
+		return $this->has(Parameter\JWKParameter::P_USE);
376
+	}
377
+
378
+	/**
379
+	 * Get the public key use parameter.
380
+	 *
381
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
382
+	 * @throws \LogicException           If the parameter is not present
383
+	 *
384
+	 * @return Parameter\PublicKeyUseParameter
385
+	 */
386
+	public function publicKeyUseParameter(): Parameter\PublicKeyUseParameter
387
+	{
388
+		return self::_checkType($this->get(Parameter\JWKParameter::P_USE),
389
+			Parameter\PublicKeyUseParameter::class);
390
+	}
391
+
392
+	/**
393
+	 * Check whether the second factor CRT exponent parameter is present.
394
+	 *
395
+	 * @return bool
396
+	 */
397
+	public function hasSecondFactorCRTExponentParameter(): bool
398
+	{
399
+		return $this->has(Parameter\JWKParameter::P_DQ);
400
+	}
401
+
402
+	/**
403
+	 * Get the second factor CRT exponent parameter.
404
+	 *
405
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
406
+	 * @throws \LogicException           If the parameter is not present
407
+	 *
408
+	 * @return Parameter\SecondFactorCRTExponentParameter
409
+	 */
410
+	public function secondFactorCRTExponentParameter(): Parameter\SecondFactorCRTExponentParameter
411
+	{
412
+		return self::_checkType($this->get(Parameter\JWKParameter::P_DQ),
413
+			Parameter\SecondFactorCRTExponentParameter::class);
414
+	}
415
+
416
+	/**
417
+	 * Check whether the second prime factor parameter is present.
418
+	 *
419
+	 * @return bool
420
+	 */
421
+	public function hasSecondPrimeFactorParameter(): bool
422
+	{
423
+		return $this->has(Parameter\JWKParameter::P_Q);
424
+	}
425
+
426
+	/**
427
+	 * Get the second prime factor parameter.
428
+	 *
429
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
430
+	 * @throws \LogicException           If the parameter is not present
431
+	 *
432
+	 * @return Parameter\SecondPrimeFactorParameter
433
+	 */
434
+	public function secondPrimeFactorParameter(): Parameter\SecondPrimeFactorParameter
435
+	{
436
+		return self::_checkType($this->get(Parameter\JWKParameter::P_Q),
437
+			Parameter\SecondPrimeFactorParameter::class);
438
+	}
439
+
440
+	/**
441
+	 * Check whether the X.509 certificate chain parameter is present.
442
+	 *
443
+	 * @return bool
444
+	 */
445
+	public function hasX509CertificateChainParameter(): bool
446
+	{
447
+		return $this->has(Parameter\JWKParameter::P_X5C);
448
+	}
449
+
450
+	/**
451
+	 * Get the X.509 certificate chain parameter.
452
+	 *
453
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
454
+	 * @throws \LogicException           If the parameter is not present
455
+	 *
456
+	 * @return Parameter\X509CertificateChainParameter
457
+	 */
458
+	public function X509CertificateChainParameter(): Parameter\X509CertificateChainParameter
459
+	{
460
+		return self::_checkType($this->get(Parameter\JWKParameter::P_X5C),
461
+			Parameter\X509CertificateChainParameter::class);
462
+	}
463
+
464
+	/**
465
+	 * Check whether the X.509 certificate SHA-1 thumbprint parameter is
466
+	 * present.
467
+	 *
468
+	 * @return bool
469
+	 */
470
+	public function hasX509CertificateSHA1ThumbprintParameter(): bool
471
+	{
472
+		return $this->has(Parameter\JWKParameter::P_X5T);
473
+	}
474
+
475
+	/**
476
+	 * Get the X.509 certificate SHA-1 thumbprint parameter.
477
+	 *
478
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
479
+	 * @throws \LogicException           If the parameter is not present
480
+	 *
481
+	 * @return Parameter\X509CertificateSHA1ThumbprintParameter
482
+	 */
483
+	public function X509CertificateSHA1ThumbprintParameter(): Parameter\X509CertificateSHA1ThumbprintParameter
484
+	{
485
+		return self::_checkType($this->get(Parameter\JWKParameter::P_X5T),
486
+			Parameter\X509CertificateSHA1ThumbprintParameter::class);
487
+	}
488
+
489
+	/**
490
+	 * Check whether the X.509 certificate SHA-256 thumbprint parameter is
491
+	 * present.
492
+	 *
493
+	 * @return bool
494
+	 */
495
+	public function hasX509CertificateSHA256ThumbprintParameter(): bool
496
+	{
497
+		return $this->has(Parameter\JWKParameter::P_X5TS256);
498
+	}
499
+
500
+	/**
501
+	 * Get the X.509 certificate SHA-256 thumbprint parameter.
502
+	 *
503
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
504
+	 * @throws \LogicException           If the parameter is not present
505
+	 *
506
+	 * @return Parameter\X509CertificateSHA256ThumbprintParameter
507
+	 */
508
+	public function X509CertificateSHA256ThumbprintParameter(): Parameter\X509CertificateSHA256ThumbprintParameter
509
+	{
510
+		return self::_checkType($this->get(Parameter\JWKParameter::P_X5TS256),
511
+			Parameter\X509CertificateSHA256ThumbprintParameter::class);
512
+	}
513
+
514
+	/**
515
+	 * Check whether the X.509 URL parameter is present.
516
+	 *
517
+	 * @return bool
518
+	 */
519
+	public function hasX509URLParameter(): bool
520
+	{
521
+		return $this->has(Parameter\JWKParameter::P_X5U);
522
+	}
523
+
524
+	/**
525
+	 * Get the X.509 URL parameter.
526
+	 *
527
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
528
+	 * @throws \LogicException           If the parameter is not present
529
+	 *
530
+	 * @return Parameter\X509URLParameter
531
+	 */
532
+	public function X509URLParameter(): Parameter\X509URLParameter
533
+	{
534
+		return self::_checkType($this->get(Parameter\JWKParameter::P_X5U),
535
+			Parameter\X509URLParameter::class);
536
+	}
537
+
538
+	/**
539
+	 * Check whether the X coordinate parameter is present.
540
+	 *
541
+	 * @return bool
542
+	 */
543
+	public function hasXCoordinateParameter(): bool
544
+	{
545
+		return $this->has(Parameter\JWKParameter::P_X);
546
+	}
547
+
548
+	/**
549
+	 * Get the X coordinate parameter.
550
+	 *
551
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
552
+	 * @throws \LogicException           If the parameter is not present
553
+	 *
554
+	 * @return Parameter\XCoordinateParameter
555
+	 */
556
+	public function XCoordinateParameter(): Parameter\XCoordinateParameter
557
+	{
558
+		return self::_checkType($this->get(Parameter\JWKParameter::P_X),
559
+			Parameter\XCoordinateParameter::class);
560
+	}
561
+
562
+	/**
563
+	 * Check whether the Y coordinate parameter is present.
564
+	 *
565
+	 * @return bool
566
+	 */
567
+	public function hasYCoordinateParameter(): bool
568
+	{
569
+		return $this->has(Parameter\JWKParameter::P_Y);
570
+	}
571
+
572
+	/**
573
+	 * Get the Y coordinate parameter.
574
+	 *
575
+	 * @throws \UnexpectedValueException If the parameter has a wrong class
576
+	 * @throws \LogicException           If the parameter is not present
577
+	 *
578
+	 * @return Parameter\YCoordinateParameter
579
+	 */
580
+	public function YCoordinateParameter(): Parameter\YCoordinateParameter
581
+	{
582
+		return self::_checkType($this->get(Parameter\JWKParameter::P_Y),
583
+			Parameter\YCoordinateParameter::class);
584
+	}
585
+
586
+	/**
587
+	 * Check that the parameter is an instance of the given class.
588
+	 *
589
+	 * @param Parameter\JWKParameter $param Parameter
590
+	 * @param string                 $cls   Class name
591
+	 *
592
+	 * @throws \UnexpectedValueException
593
+	 *
594
+	 * @return Parameter\JWKParameter
595
+	 */
596
+	private static function _checkType(Parameter\JWKParameter $param, string $cls): Parameter\JWKParameter
597
+	{
598
+		if (!$param instanceof $cls) {
599
+			throw new \UnexpectedValueException(
600
+				"{$cls} expected, got " . get_class($param));
601
+		}
602
+		return $param;
603
+	}
604 604
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/JWK.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -14,197 +14,197 @@
 block discarded – undo
14 14
  */
15 15
 class JWK implements \Countable, \IteratorAggregate
16 16
 {
17
-    use TypedJWK;
18
-
19
-    /**
20
-     * Parameters.
21
-     *
22
-     * @var JWKParameter[]
23
-     */
24
-    protected $_parameters;
25
-
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param JWKParameter ...$params
30
-     */
31
-    public function __construct(JWKParameter ...$params)
32
-    {
33
-        $this->_parameters = [];
34
-        foreach ($params as $param) {
35
-            $this->_parameters[$param->name()] = $param;
36
-        }
37
-    }
38
-
39
-    /**
40
-     * Initialize from an array representing a JSON object.
41
-     *
42
-     * @param array $members
43
-     *
44
-     * @return self
45
-     */
46
-    public static function fromArray(array $members): self
47
-    {
48
-        $params = [];
49
-        foreach ($members as $name => $value) {
50
-            $params[] = JWKParameter::fromNameAndValue($name, $value);
51
-        }
52
-        return new static(...$params);
53
-    }
54
-
55
-    /**
56
-     * Initialize from a JSON string.
57
-     *
58
-     * @param string $json
59
-     *
60
-     * @throws \UnexpectedValueException
61
-     *
62
-     * @return self
63
-     */
64
-    public static function fromJSON(string $json): self
65
-    {
66
-        $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
67
-        if (!is_array($members)) {
68
-            throw new \UnexpectedValueException('Invalid JSON.');
69
-        }
70
-        return static::fromArray($members);
71
-    }
72
-
73
-    /**
74
-     * Initialize from another JWK.
75
-     *
76
-     * Allows casting to subclass by late static binding.
77
-     *
78
-     * @param JWK $jwk
79
-     *
80
-     * @return self
81
-     */
82
-    public static function fromJWK(JWK $jwk): self
83
-    {
84
-        return new static(...array_values($jwk->_parameters));
85
-    }
86
-
87
-    /**
88
-     * Get self with parameters added.
89
-     *
90
-     * @param JWKParameter ...$params
91
-     *
92
-     * @return self
93
-     */
94
-    public function withParameters(JWKParameter ...$params): self
95
-    {
96
-        $obj = clone $this;
97
-        foreach ($params as $param) {
98
-            $obj->_parameters[$param->name()] = $param;
99
-        }
100
-        return $obj;
101
-    }
102
-
103
-    /**
104
-     * Get all parameters.
105
-     *
106
-     * @return JWKParameter[]
107
-     */
108
-    public function parameters(): array
109
-    {
110
-        return array_values($this->_parameters);
111
-    }
112
-
113
-    /**
114
-     * Get self with given key ID added to parameters.
115
-     *
116
-     * @param string $id Key ID as a string
117
-     *
118
-     * @return self
119
-     */
120
-    public function withKeyID(string $id): self
121
-    {
122
-        return $this->withParameters(new KeyIDParameter($id));
123
-    }
124
-
125
-    /**
126
-     * Whether parameters are present.
127
-     *
128
-     * Returns false if any of the given parameters is not set.
129
-     *
130
-     * @param string ...$names Parameter names
131
-     *
132
-     * @return bool
133
-     */
134
-    public function has(string ...$names): bool
135
-    {
136
-        foreach ($names as $name) {
137
-            if (!isset($this->_parameters[$name])) {
138
-                return false;
139
-            }
140
-        }
141
-        return true;
142
-    }
143
-
144
-    /**
145
-     * Get a parameter.
146
-     *
147
-     * @param string $name Parameter name
148
-     *
149
-     * @throws \LogicException
150
-     *
151
-     * @return JWKParameter
152
-     */
153
-    public function get(string $name): JWKParameter
154
-    {
155
-        if (!$this->has($name)) {
156
-            throw new \LogicException("Parameter {$name} doesn't exists.");
157
-        }
158
-        return $this->_parameters[$name];
159
-    }
160
-
161
-    /**
162
-     * Convert to array.
163
-     *
164
-     * @return array Parameter values keyed by parameter names
165
-     */
166
-    public function toArray(): array
167
-    {
168
-        $a = [];
169
-        foreach ($this->_parameters as $param) {
170
-            $a[$param->name()] = $param->value();
171
-        }
172
-        return $a;
173
-    }
174
-
175
-    /**
176
-     * Convert to JSON.
177
-     *
178
-     * @return string
179
-     */
180
-    public function toJSON(): string
181
-    {
182
-        $data = $this->toArray();
183
-        if (empty($data)) {
184
-            return '';
185
-        }
186
-        return json_encode((object) $data, JSON_UNESCAPED_SLASHES);
187
-    }
188
-
189
-    /**
190
-     * Get the number of parameters.
191
-     *
192
-     * @see \Countable::count()
193
-     */
194
-    public function count(): int
195
-    {
196
-        return count($this->_parameters);
197
-    }
198
-
199
-    /**
200
-     * Get iterator for the parameters.
201
-     *
202
-     * @see \IteratorAggregate::getIterator()
203
-     *
204
-     * @return \ArrayIterator
205
-     */
206
-    public function getIterator(): \ArrayIterator
207
-    {
208
-        return new \ArrayIterator($this->_parameters);
209
-    }
17
+	use TypedJWK;
18
+
19
+	/**
20
+	 * Parameters.
21
+	 *
22
+	 * @var JWKParameter[]
23
+	 */
24
+	protected $_parameters;
25
+
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param JWKParameter ...$params
30
+	 */
31
+	public function __construct(JWKParameter ...$params)
32
+	{
33
+		$this->_parameters = [];
34
+		foreach ($params as $param) {
35
+			$this->_parameters[$param->name()] = $param;
36
+		}
37
+	}
38
+
39
+	/**
40
+	 * Initialize from an array representing a JSON object.
41
+	 *
42
+	 * @param array $members
43
+	 *
44
+	 * @return self
45
+	 */
46
+	public static function fromArray(array $members): self
47
+	{
48
+		$params = [];
49
+		foreach ($members as $name => $value) {
50
+			$params[] = JWKParameter::fromNameAndValue($name, $value);
51
+		}
52
+		return new static(...$params);
53
+	}
54
+
55
+	/**
56
+	 * Initialize from a JSON string.
57
+	 *
58
+	 * @param string $json
59
+	 *
60
+	 * @throws \UnexpectedValueException
61
+	 *
62
+	 * @return self
63
+	 */
64
+	public static function fromJSON(string $json): self
65
+	{
66
+		$members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
67
+		if (!is_array($members)) {
68
+			throw new \UnexpectedValueException('Invalid JSON.');
69
+		}
70
+		return static::fromArray($members);
71
+	}
72
+
73
+	/**
74
+	 * Initialize from another JWK.
75
+	 *
76
+	 * Allows casting to subclass by late static binding.
77
+	 *
78
+	 * @param JWK $jwk
79
+	 *
80
+	 * @return self
81
+	 */
82
+	public static function fromJWK(JWK $jwk): self
83
+	{
84
+		return new static(...array_values($jwk->_parameters));
85
+	}
86
+
87
+	/**
88
+	 * Get self with parameters added.
89
+	 *
90
+	 * @param JWKParameter ...$params
91
+	 *
92
+	 * @return self
93
+	 */
94
+	public function withParameters(JWKParameter ...$params): self
95
+	{
96
+		$obj = clone $this;
97
+		foreach ($params as $param) {
98
+			$obj->_parameters[$param->name()] = $param;
99
+		}
100
+		return $obj;
101
+	}
102
+
103
+	/**
104
+	 * Get all parameters.
105
+	 *
106
+	 * @return JWKParameter[]
107
+	 */
108
+	public function parameters(): array
109
+	{
110
+		return array_values($this->_parameters);
111
+	}
112
+
113
+	/**
114
+	 * Get self with given key ID added to parameters.
115
+	 *
116
+	 * @param string $id Key ID as a string
117
+	 *
118
+	 * @return self
119
+	 */
120
+	public function withKeyID(string $id): self
121
+	{
122
+		return $this->withParameters(new KeyIDParameter($id));
123
+	}
124
+
125
+	/**
126
+	 * Whether parameters are present.
127
+	 *
128
+	 * Returns false if any of the given parameters is not set.
129
+	 *
130
+	 * @param string ...$names Parameter names
131
+	 *
132
+	 * @return bool
133
+	 */
134
+	public function has(string ...$names): bool
135
+	{
136
+		foreach ($names as $name) {
137
+			if (!isset($this->_parameters[$name])) {
138
+				return false;
139
+			}
140
+		}
141
+		return true;
142
+	}
143
+
144
+	/**
145
+	 * Get a parameter.
146
+	 *
147
+	 * @param string $name Parameter name
148
+	 *
149
+	 * @throws \LogicException
150
+	 *
151
+	 * @return JWKParameter
152
+	 */
153
+	public function get(string $name): JWKParameter
154
+	{
155
+		if (!$this->has($name)) {
156
+			throw new \LogicException("Parameter {$name} doesn't exists.");
157
+		}
158
+		return $this->_parameters[$name];
159
+	}
160
+
161
+	/**
162
+	 * Convert to array.
163
+	 *
164
+	 * @return array Parameter values keyed by parameter names
165
+	 */
166
+	public function toArray(): array
167
+	{
168
+		$a = [];
169
+		foreach ($this->_parameters as $param) {
170
+			$a[$param->name()] = $param->value();
171
+		}
172
+		return $a;
173
+	}
174
+
175
+	/**
176
+	 * Convert to JSON.
177
+	 *
178
+	 * @return string
179
+	 */
180
+	public function toJSON(): string
181
+	{
182
+		$data = $this->toArray();
183
+		if (empty($data)) {
184
+			return '';
185
+		}
186
+		return json_encode((object) $data, JSON_UNESCAPED_SLASHES);
187
+	}
188
+
189
+	/**
190
+	 * Get the number of parameters.
191
+	 *
192
+	 * @see \Countable::count()
193
+	 */
194
+	public function count(): int
195
+	{
196
+		return count($this->_parameters);
197
+	}
198
+
199
+	/**
200
+	 * Get iterator for the parameters.
201
+	 *
202
+	 * @see \IteratorAggregate::getIterator()
203
+	 *
204
+	 * @return \ArrayIterator
205
+	 */
206
+	public function getIterator(): \ArrayIterator
207
+	{
208
+		return new \ArrayIterator($this->_parameters);
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/Asymmetric/PublicKeyJWK.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -18,42 +18,42 @@
 block discarded – undo
18 18
  */
19 19
 abstract class PublicKeyJWK extends JWK
20 20
 {
21
-    /**
22
-     * Convert public key to PEM.
23
-     *
24
-     * @return PEM
25
-     */
26
-    abstract public function toPEM(): PEM;
21
+	/**
22
+	 * Convert public key to PEM.
23
+	 *
24
+	 * @return PEM
25
+	 */
26
+	abstract public function toPEM(): PEM;
27 27
 
28
-    /**
29
-     * Initialize from a PublicKey object.
30
-     *
31
-     * @param PublicKey $pub_key Public key
32
-     *
33
-     * @throws \UnexpectedValueException
34
-     *
35
-     * @return self
36
-     */
37
-    public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
38
-    {
39
-        if ($pub_key instanceof RSAPublicKey) {
40
-            return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
41
-        }
42
-        if ($pub_key instanceof ECPublicKey) {
43
-            return ECPublicKeyJWK::fromECPublicKey($pub_key);
44
-        }
45
-        throw new \UnexpectedValueException('Unsupported public key.');
46
-    }
28
+	/**
29
+	 * Initialize from a PublicKey object.
30
+	 *
31
+	 * @param PublicKey $pub_key Public key
32
+	 *
33
+	 * @throws \UnexpectedValueException
34
+	 *
35
+	 * @return self
36
+	 */
37
+	public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
38
+	{
39
+		if ($pub_key instanceof RSAPublicKey) {
40
+			return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
41
+		}
42
+		if ($pub_key instanceof ECPublicKey) {
43
+			return ECPublicKeyJWK::fromECPublicKey($pub_key);
44
+		}
45
+		throw new \UnexpectedValueException('Unsupported public key.');
46
+	}
47 47
 
48
-    /**
49
-     * Initialize from a PublicKeyInfo object.
50
-     *
51
-     * @param PublicKeyInfo $pki Public key info
52
-     *
53
-     * @return self
54
-     */
55
-    public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
56
-    {
57
-        return self::fromPublicKey($pki->publicKey());
58
-    }
48
+	/**
49
+	 * Initialize from a PublicKeyInfo object.
50
+	 *
51
+	 * @param PublicKeyInfo $pki Public key info
52
+	 *
53
+	 * @return self
54
+	 */
55
+	public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
56
+	{
57
+		return self::fromPublicKey($pki->publicKey());
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Asymmetric;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/Asymmetric/PrivateKeyJWK.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,49 +18,49 @@
 block discarded – undo
18 18
  */
19 19
 abstract class PrivateKeyJWK extends JWK
20 20
 {
21
-    /**
22
-     * Get the public key component of the asymmetric key pair.
23
-     *
24
-     * @return PublicKeyJWK
25
-     */
26
-    abstract public function publicKey(): PublicKeyJWK;
21
+	/**
22
+	 * Get the public key component of the asymmetric key pair.
23
+	 *
24
+	 * @return PublicKeyJWK
25
+	 */
26
+	abstract public function publicKey(): PublicKeyJWK;
27 27
 
28
-    /**
29
-     * Convert private key to PEM.
30
-     *
31
-     * @return PEM
32
-     */
33
-    abstract public function toPEM(): PEM;
28
+	/**
29
+	 * Convert private key to PEM.
30
+	 *
31
+	 * @return PEM
32
+	 */
33
+	abstract public function toPEM(): PEM;
34 34
 
35
-    /**
36
-     * Initialize from a PrivateKey object.
37
-     *
38
-     * @param PrivateKey $priv_key Private key
39
-     *
40
-     * @throws \UnexpectedValueException
41
-     *
42
-     * @return self
43
-     */
44
-    public static function fromPrivateKey(PrivateKey $priv_key): PrivateKeyJWK
45
-    {
46
-        if ($priv_key instanceof RSAPrivateKey) {
47
-            return RSAPrivateKeyJWK::fromRSAPrivateKey($priv_key);
48
-        }
49
-        if ($priv_key instanceof ECPrivateKey) {
50
-            return ECPrivateKeyJWK::fromECPrivateKey($priv_key);
51
-        }
52
-        throw new \UnexpectedValueException('Unsupported private key.');
53
-    }
35
+	/**
36
+	 * Initialize from a PrivateKey object.
37
+	 *
38
+	 * @param PrivateKey $priv_key Private key
39
+	 *
40
+	 * @throws \UnexpectedValueException
41
+	 *
42
+	 * @return self
43
+	 */
44
+	public static function fromPrivateKey(PrivateKey $priv_key): PrivateKeyJWK
45
+	{
46
+		if ($priv_key instanceof RSAPrivateKey) {
47
+			return RSAPrivateKeyJWK::fromRSAPrivateKey($priv_key);
48
+		}
49
+		if ($priv_key instanceof ECPrivateKey) {
50
+			return ECPrivateKeyJWK::fromECPrivateKey($priv_key);
51
+		}
52
+		throw new \UnexpectedValueException('Unsupported private key.');
53
+	}
54 54
 
55
-    /**
56
-     * Initialize from a PrivateKeyInfo object.
57
-     *
58
-     * @param PrivateKeyInfo $pki PrivateKeyInfo
59
-     *
60
-     * @return self
61
-     */
62
-    public static function fromPrivateKeyInfo(PrivateKeyInfo $pki): PrivateKeyJWK
63
-    {
64
-        return self::fromPrivateKey($pki->privateKey());
65
-    }
55
+	/**
56
+	 * Initialize from a PrivateKeyInfo object.
57
+	 *
58
+	 * @param PrivateKeyInfo $pki PrivateKeyInfo
59
+	 *
60
+	 * @return self
61
+	 */
62
+	public static function fromPrivateKeyInfo(PrivateKeyInfo $pki): PrivateKeyJWK
63
+	{
64
+		return self::fromPrivateKey($pki->privateKey());
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\Asymmetric;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWK/EC/ECPublicKeyJWK.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -23,85 +23,85 @@
 block discarded – undo
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 = [
32
-        JWKParameter::PARAM_KEY_TYPE,
33
-        JWKParameter::PARAM_CURVE,
34
-        JWKParameter::PARAM_X_COORDINATE,
35
-    ];
26
+	/**
27
+	 * Parameter names managed by this class.
28
+	 *
29
+	 * @var string[]
30
+	 */
31
+	const MANAGED_PARAMS = [
32
+		JWKParameter::PARAM_KEY_TYPE,
33
+		JWKParameter::PARAM_CURVE,
34
+		JWKParameter::PARAM_X_COORDINATE,
35
+	];
36 36
 
37
-    /**
38
-     * Constructor.
39
-     *
40
-     * @param JWKParameter ...$params
41
-     *
42
-     * @throws \UnexpectedValueException If missing required parameter
43
-     */
44
-    public function __construct(JWKParameter ...$params)
45
-    {
46
-        parent::__construct(...$params);
47
-        foreach (self::MANAGED_PARAMS as $name) {
48
-            if (!$this->has($name)) {
49
-                throw new \UnexpectedValueException(
50
-                    "Missing '{$name}' parameter.");
51
-            }
52
-        }
53
-        if (KeyTypeParameter::TYPE_EC !== $this->keyTypeParameter()->value()) {
54
-            throw new \UnexpectedValueException('Invalid key type.');
55
-        }
56
-    }
37
+	/**
38
+	 * Constructor.
39
+	 *
40
+	 * @param JWKParameter ...$params
41
+	 *
42
+	 * @throws \UnexpectedValueException If missing required parameter
43
+	 */
44
+	public function __construct(JWKParameter ...$params)
45
+	{
46
+		parent::__construct(...$params);
47
+		foreach (self::MANAGED_PARAMS as $name) {
48
+			if (!$this->has($name)) {
49
+				throw new \UnexpectedValueException(
50
+					"Missing '{$name}' parameter.");
51
+			}
52
+		}
53
+		if (KeyTypeParameter::TYPE_EC !== $this->keyTypeParameter()->value()) {
54
+			throw new \UnexpectedValueException('Invalid key type.');
55
+		}
56
+	}
57 57
 
58
-    /**
59
-     * Initialize from ECPublicKey.
60
-     *
61
-     * @param ECPublicKey $pk
62
-     *
63
-     * @throws \UnexpectedValueException
64
-     *
65
-     * @return self
66
-     */
67
-    public static function fromECPublicKey(ECPublicKey $pk): self
68
-    {
69
-        if (!$pk->hasNamedCurve()) {
70
-            throw new \UnexpectedValueException('No curve name.');
71
-        }
72
-        $curve = CurveParameter::fromOID($pk->namedCurve());
73
-        [$x, $y] = $pk->curvePointOctets();
74
-        $xcoord = XCoordinateParameter::fromString($x);
75
-        $ycoord = YCoordinateParameter::fromString($y);
76
-        $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC);
77
-        return new self($key_type, $curve, $xcoord, $ycoord);
78
-    }
58
+	/**
59
+	 * Initialize from ECPublicKey.
60
+	 *
61
+	 * @param ECPublicKey $pk
62
+	 *
63
+	 * @throws \UnexpectedValueException
64
+	 *
65
+	 * @return self
66
+	 */
67
+	public static function fromECPublicKey(ECPublicKey $pk): self
68
+	{
69
+		if (!$pk->hasNamedCurve()) {
70
+			throw new \UnexpectedValueException('No curve name.');
71
+		}
72
+		$curve = CurveParameter::fromOID($pk->namedCurve());
73
+		[$x, $y] = $pk->curvePointOctets();
74
+		$xcoord = XCoordinateParameter::fromString($x);
75
+		$ycoord = YCoordinateParameter::fromString($y);
76
+		$key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_EC);
77
+		return new self($key_type, $curve, $xcoord, $ycoord);
78
+	}
79 79
 
80
-    /**
81
-     * Initialize from PEM.
82
-     *
83
-     * @param PEM $pem
84
-     *
85
-     * @return self
86
-     */
87
-    public static function fromPEM(PEM $pem): self
88
-    {
89
-        return self::fromECPublicKey(ECPublicKey::fromPEM($pem));
90
-    }
80
+	/**
81
+	 * Initialize from PEM.
82
+	 *
83
+	 * @param PEM $pem
84
+	 *
85
+	 * @return self
86
+	 */
87
+	public static function fromPEM(PEM $pem): self
88
+	{
89
+		return self::fromECPublicKey(ECPublicKey::fromPEM($pem));
90
+	}
91 91
 
92
-    /**
93
-     * Convert EC public key to PEM.
94
-     *
95
-     * @return PEM
96
-     */
97
-    public function toPEM(): PEM
98
-    {
99
-        $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value());
100
-        $x = ECConversion::octetsToNumber(
101
-            $this->XCoordinateParameter()->coordinateOctets());
102
-        $y = ECConversion::octetsToNumber(
103
-            $this->YCoordinateParameter()->coordinateOctets());
104
-        $ec = ECPublicKey::fromCoordinates($x, $y, $curve_oid);
105
-        return $ec->publicKeyInfo()->toPEM();
106
-    }
92
+	/**
93
+	 * Convert EC public key to PEM.
94
+	 *
95
+	 * @return PEM
96
+	 */
97
+	public function toPEM(): PEM
98
+	{
99
+		$curve_oid = CurveParameter::nameToOID($this->curveParameter()->value());
100
+		$x = ECConversion::octetsToNumber(
101
+			$this->XCoordinateParameter()->coordinateOctets());
102
+		$y = ECConversion::octetsToNumber(
103
+			$this->YCoordinateParameter()->coordinateOctets());
104
+		$ec = ECPublicKey::fromCoordinates($x, $y, $curve_oid);
105
+		return $ec->publicKeyInfo()->toPEM();
106
+	}
107 107
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWK\EC;
6 6
 
Please login to merge, or discard this patch.