@@ -22,77 +22,77 @@ |
||
22 | 22 | */ |
23 | 23 | class RSAPublicKeyJWK extends PublicKeyJWK |
24 | 24 | { |
25 | - /** |
|
26 | - * Parameter names managed by this class. |
|
27 | - * |
|
28 | - * @internal |
|
29 | - * |
|
30 | - * @var string[] |
|
31 | - */ |
|
32 | - const MANAGED_PARAMS = [ |
|
33 | - JWKParameter::PARAM_KEY_TYPE, |
|
34 | - JWKParameter::PARAM_MODULUS, |
|
35 | - JWKParameter::PARAM_EXPONENT, |
|
36 | - ]; |
|
25 | + /** |
|
26 | + * Parameter names managed by this class. |
|
27 | + * |
|
28 | + * @internal |
|
29 | + * |
|
30 | + * @var string[] |
|
31 | + */ |
|
32 | + const MANAGED_PARAMS = [ |
|
33 | + JWKParameter::PARAM_KEY_TYPE, |
|
34 | + JWKParameter::PARAM_MODULUS, |
|
35 | + JWKParameter::PARAM_EXPONENT, |
|
36 | + ]; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param JWKParameter ...$params |
|
42 | - * |
|
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( |
|
51 | - "Missing '{$name}' parameter."); |
|
52 | - } |
|
53 | - } |
|
54 | - if (KeyTypeParameter::TYPE_RSA !== $this->keyTypeParameter()->value()) { |
|
55 | - throw new \UnexpectedValueException('Invalid key type.'); |
|
56 | - } |
|
57 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param JWKParameter ...$params |
|
42 | + * |
|
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( |
|
51 | + "Missing '{$name}' parameter."); |
|
52 | + } |
|
53 | + } |
|
54 | + if (KeyTypeParameter::TYPE_RSA !== $this->keyTypeParameter()->value()) { |
|
55 | + throw new \UnexpectedValueException('Invalid key type.'); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Initialize from RSAPublicKey. |
|
61 | - * |
|
62 | - * @param RSAPublicKey $pk |
|
63 | - * |
|
64 | - * @return self |
|
65 | - */ |
|
66 | - public static function fromRSAPublicKey(RSAPublicKey $pk): self |
|
67 | - { |
|
68 | - $n = ModulusParameter::fromNumber($pk->modulus()); |
|
69 | - $e = ExponentParameter::fromNumber($pk->publicExponent()); |
|
70 | - $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA); |
|
71 | - return new self($key_type, $n, $e); |
|
72 | - } |
|
59 | + /** |
|
60 | + * Initialize from RSAPublicKey. |
|
61 | + * |
|
62 | + * @param RSAPublicKey $pk |
|
63 | + * |
|
64 | + * @return self |
|
65 | + */ |
|
66 | + public static function fromRSAPublicKey(RSAPublicKey $pk): self |
|
67 | + { |
|
68 | + $n = ModulusParameter::fromNumber($pk->modulus()); |
|
69 | + $e = ExponentParameter::fromNumber($pk->publicExponent()); |
|
70 | + $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA); |
|
71 | + return new self($key_type, $n, $e); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Initialize from PEM. |
|
76 | - * |
|
77 | - * @param PEM $pem |
|
78 | - * |
|
79 | - * @return self |
|
80 | - */ |
|
81 | - public static function fromPEM(PEM $pem): self |
|
82 | - { |
|
83 | - return self::fromRSAPublicKey(RSAPublicKey::fromPEM($pem)); |
|
84 | - } |
|
74 | + /** |
|
75 | + * Initialize from PEM. |
|
76 | + * |
|
77 | + * @param PEM $pem |
|
78 | + * |
|
79 | + * @return self |
|
80 | + */ |
|
81 | + public static function fromPEM(PEM $pem): self |
|
82 | + { |
|
83 | + return self::fromRSAPublicKey(RSAPublicKey::fromPEM($pem)); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Convert JWK to PEM. |
|
88 | - * |
|
89 | - * @return PEM |
|
90 | - */ |
|
91 | - public function toPEM(): PEM |
|
92 | - { |
|
93 | - $n = $this->modulusParameter()->number()->base10(); |
|
94 | - $e = $this->exponentParameter()->number()->base10(); |
|
95 | - $pk = new RSAPublicKey($n, $e); |
|
96 | - return PublicKeyInfo::fromPublicKey($pk)->toPEM(); |
|
97 | - } |
|
86 | + /** |
|
87 | + * Convert JWK to PEM. |
|
88 | + * |
|
89 | + * @return PEM |
|
90 | + */ |
|
91 | + public function toPEM(): PEM |
|
92 | + { |
|
93 | + $n = $this->modulusParameter()->number()->base10(); |
|
94 | + $e = $this->exponentParameter()->number()->base10(); |
|
95 | + $pk = new RSAPublicKey($n, $e); |
|
96 | + return PublicKeyInfo::fromPublicKey($pk)->toPEM(); |
|
97 | + } |
|
98 | 98 | } |
@@ -29,112 +29,112 @@ |
||
29 | 29 | */ |
30 | 30 | class RSAPrivateKeyJWK extends PrivateKeyJWK |
31 | 31 | { |
32 | - /** |
|
33 | - * Parameter names managed by this class. |
|
34 | - * |
|
35 | - * @internal |
|
36 | - * |
|
37 | - * @var string[] |
|
38 | - */ |
|
39 | - const MANAGED_PARAMS = [ |
|
40 | - JWKParameter::PARAM_KEY_TYPE, |
|
41 | - JWKParameter::PARAM_MODULUS, |
|
42 | - JWKParameter::PARAM_EXPONENT, |
|
43 | - JWKParameter::PARAM_PRIVATE_EXPONENT, |
|
44 | - JWKParameter::PARAM_FIRST_PRIME_FACTOR, |
|
45 | - JWKParameter::PARAM_SECOND_PRIME_FACTOR, |
|
46 | - JWKParameter::PARAM_FIRST_FACTOR_CRT_EXPONENT, |
|
47 | - JWKParameter::PARAM_SECOND_FACTOR_CRT_EXPONENT, |
|
48 | - JWKParameter::PARAM_FIRST_CRT_COEFFICIENT, |
|
49 | - ]; |
|
32 | + /** |
|
33 | + * Parameter names managed by this class. |
|
34 | + * |
|
35 | + * @internal |
|
36 | + * |
|
37 | + * @var string[] |
|
38 | + */ |
|
39 | + const MANAGED_PARAMS = [ |
|
40 | + JWKParameter::PARAM_KEY_TYPE, |
|
41 | + JWKParameter::PARAM_MODULUS, |
|
42 | + JWKParameter::PARAM_EXPONENT, |
|
43 | + JWKParameter::PARAM_PRIVATE_EXPONENT, |
|
44 | + JWKParameter::PARAM_FIRST_PRIME_FACTOR, |
|
45 | + JWKParameter::PARAM_SECOND_PRIME_FACTOR, |
|
46 | + JWKParameter::PARAM_FIRST_FACTOR_CRT_EXPONENT, |
|
47 | + JWKParameter::PARAM_SECOND_FACTOR_CRT_EXPONENT, |
|
48 | + JWKParameter::PARAM_FIRST_CRT_COEFFICIENT, |
|
49 | + ]; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Constructor. |
|
53 | - * |
|
54 | - * @param JWKParameter ...$params |
|
55 | - * |
|
56 | - * @throws \UnexpectedValueException If missing required parameter |
|
57 | - */ |
|
58 | - public function __construct(JWKParameter ...$params) |
|
59 | - { |
|
60 | - parent::__construct(...$params); |
|
61 | - foreach (self::MANAGED_PARAMS as $name) { |
|
62 | - if (!$this->has($name)) { |
|
63 | - throw new \UnexpectedValueException( |
|
64 | - "Missing '{$name}' parameter."); |
|
65 | - } |
|
66 | - } |
|
67 | - if (KeyTypeParameter::TYPE_RSA !== $this->keyTypeParameter()->value()) { |
|
68 | - throw new \UnexpectedValueException('Invalid key type.'); |
|
69 | - } |
|
70 | - // cast private exponent to correct class |
|
71 | - $key = JWKParameter::PARAM_PRIVATE_EXPONENT; |
|
72 | - $this->_parameters[$key] = new PrivateExponentParameter( |
|
73 | - $this->_parameters[$key]->value()); |
|
74 | - } |
|
51 | + /** |
|
52 | + * Constructor. |
|
53 | + * |
|
54 | + * @param JWKParameter ...$params |
|
55 | + * |
|
56 | + * @throws \UnexpectedValueException If missing required parameter |
|
57 | + */ |
|
58 | + public function __construct(JWKParameter ...$params) |
|
59 | + { |
|
60 | + parent::__construct(...$params); |
|
61 | + foreach (self::MANAGED_PARAMS as $name) { |
|
62 | + if (!$this->has($name)) { |
|
63 | + throw new \UnexpectedValueException( |
|
64 | + "Missing '{$name}' parameter."); |
|
65 | + } |
|
66 | + } |
|
67 | + if (KeyTypeParameter::TYPE_RSA !== $this->keyTypeParameter()->value()) { |
|
68 | + throw new \UnexpectedValueException('Invalid key type.'); |
|
69 | + } |
|
70 | + // cast private exponent to correct class |
|
71 | + $key = JWKParameter::PARAM_PRIVATE_EXPONENT; |
|
72 | + $this->_parameters[$key] = new PrivateExponentParameter( |
|
73 | + $this->_parameters[$key]->value()); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Initialize from RSAPrivateKey. |
|
78 | - * |
|
79 | - * @param RSAPrivateKey $pk |
|
80 | - * |
|
81 | - * @return self |
|
82 | - */ |
|
83 | - public static function fromRSAPrivateKey(RSAPrivateKey $pk): self |
|
84 | - { |
|
85 | - $n = ModulusParameter::fromNumber($pk->modulus()); |
|
86 | - $e = ExponentParameter::fromNumber($pk->publicExponent()); |
|
87 | - $d = PrivateExponentParameter::fromNumber($pk->privateExponent()); |
|
88 | - $p = FirstPrimeFactorParameter::fromNumber($pk->prime1()); |
|
89 | - $q = SecondPrimeFactorParameter::fromNumber($pk->prime2()); |
|
90 | - $dp = FirstFactorCRTExponentParameter::fromNumber($pk->exponent1()); |
|
91 | - $dq = SecondFactorCRTExponentParameter::fromNumber($pk->exponent2()); |
|
92 | - $qi = FirstCRTCoefficientParameter::fromNumber($pk->coefficient()); |
|
93 | - $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA); |
|
94 | - return new self($key_type, $n, $e, $d, $p, $q, $dp, $dq, $qi); |
|
95 | - } |
|
76 | + /** |
|
77 | + * Initialize from RSAPrivateKey. |
|
78 | + * |
|
79 | + * @param RSAPrivateKey $pk |
|
80 | + * |
|
81 | + * @return self |
|
82 | + */ |
|
83 | + public static function fromRSAPrivateKey(RSAPrivateKey $pk): self |
|
84 | + { |
|
85 | + $n = ModulusParameter::fromNumber($pk->modulus()); |
|
86 | + $e = ExponentParameter::fromNumber($pk->publicExponent()); |
|
87 | + $d = PrivateExponentParameter::fromNumber($pk->privateExponent()); |
|
88 | + $p = FirstPrimeFactorParameter::fromNumber($pk->prime1()); |
|
89 | + $q = SecondPrimeFactorParameter::fromNumber($pk->prime2()); |
|
90 | + $dp = FirstFactorCRTExponentParameter::fromNumber($pk->exponent1()); |
|
91 | + $dq = SecondFactorCRTExponentParameter::fromNumber($pk->exponent2()); |
|
92 | + $qi = FirstCRTCoefficientParameter::fromNumber($pk->coefficient()); |
|
93 | + $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA); |
|
94 | + return new self($key_type, $n, $e, $d, $p, $q, $dp, $dq, $qi); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Initialize from PEM. |
|
99 | - * |
|
100 | - * @param PEM $pem |
|
101 | - * |
|
102 | - * @return self |
|
103 | - */ |
|
104 | - public static function fromPEM(PEM $pem): self |
|
105 | - { |
|
106 | - return self::fromRSAPrivateKey(RSAPrivateKey::fromPEM($pem)); |
|
107 | - } |
|
97 | + /** |
|
98 | + * Initialize from PEM. |
|
99 | + * |
|
100 | + * @param PEM $pem |
|
101 | + * |
|
102 | + * @return self |
|
103 | + */ |
|
104 | + public static function fromPEM(PEM $pem): self |
|
105 | + { |
|
106 | + return self::fromRSAPrivateKey(RSAPrivateKey::fromPEM($pem)); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get public key component. |
|
111 | - * |
|
112 | - * @return RSAPublicKeyJWK |
|
113 | - */ |
|
114 | - public function publicKey(): PublicKeyJWK |
|
115 | - { |
|
116 | - $kty = $this->keyTypeParameter(); |
|
117 | - $n = $this->modulusParameter(); |
|
118 | - $e = $this->exponentParameter(); |
|
119 | - return new RSAPublicKeyJWK($kty, $n, $e); |
|
120 | - } |
|
109 | + /** |
|
110 | + * Get public key component. |
|
111 | + * |
|
112 | + * @return RSAPublicKeyJWK |
|
113 | + */ |
|
114 | + public function publicKey(): PublicKeyJWK |
|
115 | + { |
|
116 | + $kty = $this->keyTypeParameter(); |
|
117 | + $n = $this->modulusParameter(); |
|
118 | + $e = $this->exponentParameter(); |
|
119 | + return new RSAPublicKeyJWK($kty, $n, $e); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Convert JWK to PEM. |
|
124 | - * |
|
125 | - * @return PEM |
|
126 | - */ |
|
127 | - public function toPEM(): PEM |
|
128 | - { |
|
129 | - $n = $this->modulusParameter()->number()->base10(); |
|
130 | - $e = $this->exponentParameter()->number()->base10(); |
|
131 | - $d = $this->privateExponentParameter()->number()->base10(); |
|
132 | - $p = $this->firstPrimeFactorParameter()->number()->base10(); |
|
133 | - $q = $this->secondPrimeFactorParameter()->number()->base10(); |
|
134 | - $dp = $this->firstFactorCRTExponentParameter()->number()->base10(); |
|
135 | - $dq = $this->secondFactorCRTExponentParameter()->number()->base10(); |
|
136 | - $qi = $this->firstCRTCoefficientParameter()->number()->base10(); |
|
137 | - $pk = new RSAPrivateKey($n, $e, $d, $p, $q, $dp, $dq, $qi); |
|
138 | - return PrivateKeyInfo::fromPrivateKey($pk)->toPEM(); |
|
139 | - } |
|
122 | + /** |
|
123 | + * Convert JWK to PEM. |
|
124 | + * |
|
125 | + * @return PEM |
|
126 | + */ |
|
127 | + public function toPEM(): PEM |
|
128 | + { |
|
129 | + $n = $this->modulusParameter()->number()->base10(); |
|
130 | + $e = $this->exponentParameter()->number()->base10(); |
|
131 | + $d = $this->privateExponentParameter()->number()->base10(); |
|
132 | + $p = $this->firstPrimeFactorParameter()->number()->base10(); |
|
133 | + $q = $this->secondPrimeFactorParameter()->number()->base10(); |
|
134 | + $dp = $this->firstFactorCRTExponentParameter()->number()->base10(); |
|
135 | + $dq = $this->secondFactorCRTExponentParameter()->number()->base10(); |
|
136 | + $qi = $this->firstCRTCoefficientParameter()->number()->base10(); |
|
137 | + $pk = new RSAPrivateKey($n, $e, $d, $p, $q, $dp, $dq, $qi); |
|
138 | + return PrivateKeyInfo::fromPrivateKey($pk)->toPEM(); |
|
139 | + } |
|
140 | 140 | } |
@@ -14,21 +14,21 @@ |
||
14 | 14 | */ |
15 | 15 | class X509CertificateChainParameter extends JWKParameter |
16 | 16 | { |
17 | - use ArrayParameterValue; |
|
17 | + use ArrayParameterValue; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param string ...$certs Base64 encoded DER certificates |
|
23 | - */ |
|
24 | - public function __construct(string ...$certs) |
|
25 | - { |
|
26 | - foreach ($certs as $cert) { |
|
27 | - if (!Base64::isValid($cert)) { |
|
28 | - throw new \UnexpectedValueException( |
|
29 | - 'Certificate must be base64 encoded.'); |
|
30 | - } |
|
31 | - } |
|
32 | - parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
33 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param string ...$certs Base64 encoded DER certificates |
|
23 | + */ |
|
24 | + public function __construct(string ...$certs) |
|
25 | + { |
|
26 | + foreach ($certs as $cert) { |
|
27 | + if (!Base64::isValid($cert)) { |
|
28 | + throw new \UnexpectedValueException( |
|
29 | + 'Certificate must be base64 encoded.'); |
|
30 | + } |
|
31 | + } |
|
32 | + parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
33 | + } |
|
34 | 34 | } |
@@ -13,24 +13,24 @@ |
||
13 | 13 | */ |
14 | 14 | class KeyOperationsParameter extends JWKParameter |
15 | 15 | { |
16 | - use ArrayParameterValue; |
|
16 | + use ArrayParameterValue; |
|
17 | 17 | |
18 | - const OP_SIGN = 'sign'; |
|
19 | - const OP_VERIFY = 'verify'; |
|
20 | - const OP_ENCRYPT = 'encrypt'; |
|
21 | - const OP_DECRYPT = 'decrypt'; |
|
22 | - const OP_WRAP_KEY = 'wrapKey'; |
|
23 | - const OP_UNWRAP_KEY = 'unwrapKey'; |
|
24 | - const OP_DERIVE_KEY = 'deriveKey'; |
|
25 | - const OP_DERIVE_BITS = 'deriveBits'; |
|
18 | + const OP_SIGN = 'sign'; |
|
19 | + const OP_VERIFY = 'verify'; |
|
20 | + const OP_ENCRYPT = 'encrypt'; |
|
21 | + const OP_DECRYPT = 'decrypt'; |
|
22 | + const OP_WRAP_KEY = 'wrapKey'; |
|
23 | + const OP_UNWRAP_KEY = 'unwrapKey'; |
|
24 | + const OP_DERIVE_KEY = 'deriveKey'; |
|
25 | + const OP_DERIVE_BITS = 'deriveBits'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Constructor. |
|
29 | - * |
|
30 | - * @param string ...$ops Key operations |
|
31 | - */ |
|
32 | - public function __construct(string ...$ops) |
|
33 | - { |
|
34 | - parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
35 | - } |
|
27 | + /** |
|
28 | + * Constructor. |
|
29 | + * |
|
30 | + * @param string ...$ops Key operations |
|
31 | + */ |
|
32 | + public function __construct(string ...$ops) |
|
33 | + { |
|
34 | + parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
35 | + } |
|
36 | 36 | } |
@@ -13,18 +13,18 @@ |
||
13 | 13 | */ |
14 | 14 | class PublicKeyUseParameter extends JWKParameter |
15 | 15 | { |
16 | - use StringParameterValue; |
|
16 | + use StringParameterValue; |
|
17 | 17 | |
18 | - const USE_SIGNATURE = 'sig'; |
|
19 | - const USE_ENCRYPTION = 'enc'; |
|
18 | + const USE_SIGNATURE = 'sig'; |
|
19 | + const USE_ENCRYPTION = 'enc'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param string $use Intended use of the public key |
|
25 | - */ |
|
26 | - public function __construct(string $use) |
|
27 | - { |
|
28 | - parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
29 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param string $use Intended use of the public key |
|
25 | + */ |
|
26 | + public function __construct(string $use) |
|
27 | + { |
|
28 | + parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
29 | + } |
|
30 | 30 | } |
@@ -13,30 +13,30 @@ |
||
13 | 13 | */ |
14 | 14 | class KeyTypeParameter extends JWKParameter |
15 | 15 | { |
16 | - use StringParameterValue; |
|
17 | - |
|
18 | - /** |
|
19 | - * Octet sequence key type. |
|
20 | - */ |
|
21 | - const TYPE_OCT = 'oct'; |
|
22 | - |
|
23 | - /** |
|
24 | - * RSA key type. |
|
25 | - */ |
|
26 | - const TYPE_RSA = 'RSA'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Elliptic curve key type. |
|
30 | - */ |
|
31 | - const TYPE_EC = 'EC'; |
|
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 | - } |
|
16 | + use StringParameterValue; |
|
17 | + |
|
18 | + /** |
|
19 | + * Octet sequence key type. |
|
20 | + */ |
|
21 | + const TYPE_OCT = 'oct'; |
|
22 | + |
|
23 | + /** |
|
24 | + * RSA key type. |
|
25 | + */ |
|
26 | + const TYPE_RSA = 'RSA'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Elliptic curve key type. |
|
30 | + */ |
|
31 | + const TYPE_EC = 'EC'; |
|
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 | + } |
|
42 | 42 | } |
@@ -14,131 +14,131 @@ |
||
14 | 14 | */ |
15 | 15 | class JWKParameter extends Parameter |
16 | 16 | { |
17 | - // registered parameter names |
|
18 | - const PARAM_KEY_TYPE = 'kty'; |
|
19 | - const PARAM_PUBLIC_KEY_USE = 'use'; |
|
20 | - const PARAM_KEY_OPERATIONS = 'key_ops'; |
|
21 | - const PARAM_ALGORITHM = 'alg'; |
|
22 | - const PARAM_KEY_ID = 'kid'; |
|
23 | - const PARAM_X509_URL = 'x5u'; |
|
24 | - const PARAM_X509_CERTIFICATE_CHAIN = 'x5c'; |
|
25 | - const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = 'x5t'; |
|
26 | - const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = 'x5t#S256'; |
|
27 | - const PARAM_CURVE = 'crv'; |
|
28 | - const PARAM_X_COORDINATE = 'x'; |
|
29 | - const PARAM_Y_COORDINATE = 'y'; |
|
30 | - const PARAM_ECC_PRIVATE_KEY = 'd'; |
|
31 | - const PARAM_MODULUS = 'n'; |
|
32 | - const PARAM_EXPONENT = 'e'; |
|
33 | - const PARAM_PRIVATE_EXPONENT = 'd'; |
|
34 | - const PARAM_FIRST_PRIME_FACTOR = 'p'; |
|
35 | - const PARAM_SECOND_PRIME_FACTOR = 'q'; |
|
36 | - const PARAM_FIRST_FACTOR_CRT_EXPONENT = 'dp'; |
|
37 | - const PARAM_SECOND_FACTOR_CRT_EXPONENT = 'dq'; |
|
38 | - const PARAM_FIRST_CRT_COEFFICIENT = 'qi'; |
|
39 | - const PARAM_OTHER_PRIMES_INFO = 'oth'; |
|
40 | - const PARAM_KEY_VALUE = 'k'; |
|
17 | + // registered parameter names |
|
18 | + const PARAM_KEY_TYPE = 'kty'; |
|
19 | + const PARAM_PUBLIC_KEY_USE = 'use'; |
|
20 | + const PARAM_KEY_OPERATIONS = 'key_ops'; |
|
21 | + const PARAM_ALGORITHM = 'alg'; |
|
22 | + const PARAM_KEY_ID = 'kid'; |
|
23 | + const PARAM_X509_URL = 'x5u'; |
|
24 | + const PARAM_X509_CERTIFICATE_CHAIN = 'x5c'; |
|
25 | + const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = 'x5t'; |
|
26 | + const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = 'x5t#S256'; |
|
27 | + const PARAM_CURVE = 'crv'; |
|
28 | + const PARAM_X_COORDINATE = 'x'; |
|
29 | + const PARAM_Y_COORDINATE = 'y'; |
|
30 | + const PARAM_ECC_PRIVATE_KEY = 'd'; |
|
31 | + const PARAM_MODULUS = 'n'; |
|
32 | + const PARAM_EXPONENT = 'e'; |
|
33 | + const PARAM_PRIVATE_EXPONENT = 'd'; |
|
34 | + const PARAM_FIRST_PRIME_FACTOR = 'p'; |
|
35 | + const PARAM_SECOND_PRIME_FACTOR = 'q'; |
|
36 | + const PARAM_FIRST_FACTOR_CRT_EXPONENT = 'dp'; |
|
37 | + const PARAM_SECOND_FACTOR_CRT_EXPONENT = 'dq'; |
|
38 | + const PARAM_FIRST_CRT_COEFFICIENT = 'qi'; |
|
39 | + const PARAM_OTHER_PRIMES_INFO = 'oth'; |
|
40 | + const PARAM_KEY_VALUE = 'k'; |
|
41 | 41 | |
42 | - // shorthand aliases for parameter names |
|
43 | - const P_KTY = self::PARAM_KEY_TYPE; |
|
44 | - const P_USE = self::PARAM_PUBLIC_KEY_USE; |
|
45 | - const P_KEY_OPS = self::PARAM_KEY_OPERATIONS; |
|
46 | - const P_ALG = self::PARAM_ALGORITHM; |
|
47 | - const P_KID = self::PARAM_KEY_ID; |
|
48 | - const P_X5U = self::PARAM_X509_URL; |
|
49 | - const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN; |
|
50 | - const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT; |
|
51 | - const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT; |
|
52 | - const P_CRV = self::PARAM_CURVE; |
|
53 | - const P_X = self::PARAM_X_COORDINATE; |
|
54 | - const P_Y = self::PARAM_Y_COORDINATE; |
|
55 | - const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY; |
|
56 | - const P_N = self::PARAM_MODULUS; |
|
57 | - const P_E = self::PARAM_EXPONENT; |
|
58 | - const P_RSA_D = self::PARAM_PRIVATE_EXPONENT; |
|
59 | - const P_P = self::PARAM_FIRST_PRIME_FACTOR; |
|
60 | - const P_Q = self::PARAM_SECOND_PRIME_FACTOR; |
|
61 | - const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT; |
|
62 | - const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT; |
|
63 | - const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT; |
|
64 | - const P_OTH = self::PARAM_OTHER_PRIMES_INFO; |
|
65 | - const P_K = self::PARAM_KEY_VALUE; |
|
42 | + // shorthand aliases for parameter names |
|
43 | + const P_KTY = self::PARAM_KEY_TYPE; |
|
44 | + const P_USE = self::PARAM_PUBLIC_KEY_USE; |
|
45 | + const P_KEY_OPS = self::PARAM_KEY_OPERATIONS; |
|
46 | + const P_ALG = self::PARAM_ALGORITHM; |
|
47 | + const P_KID = self::PARAM_KEY_ID; |
|
48 | + const P_X5U = self::PARAM_X509_URL; |
|
49 | + const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN; |
|
50 | + const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT; |
|
51 | + const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT; |
|
52 | + const P_CRV = self::PARAM_CURVE; |
|
53 | + const P_X = self::PARAM_X_COORDINATE; |
|
54 | + const P_Y = self::PARAM_Y_COORDINATE; |
|
55 | + const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY; |
|
56 | + const P_N = self::PARAM_MODULUS; |
|
57 | + const P_E = self::PARAM_EXPONENT; |
|
58 | + const P_RSA_D = self::PARAM_PRIVATE_EXPONENT; |
|
59 | + const P_P = self::PARAM_FIRST_PRIME_FACTOR; |
|
60 | + const P_Q = self::PARAM_SECOND_PRIME_FACTOR; |
|
61 | + const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT; |
|
62 | + const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT; |
|
63 | + const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT; |
|
64 | + const P_OTH = self::PARAM_OTHER_PRIMES_INFO; |
|
65 | + const P_K = self::PARAM_KEY_VALUE; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Mapping from registered JWK parameter name to class name. |
|
69 | - * |
|
70 | - * Note that ECC private key and RSA private key cannot be mapped since |
|
71 | - * they share the same parameter name 'd'. |
|
72 | - * |
|
73 | - * @internal |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - const MAP_NAME_TO_CLASS = [ |
|
78 | - self::P_KTY => KeyTypeParameter::class, |
|
79 | - self::P_USE => PublicKeyUseParameter::class, |
|
80 | - self::P_KEY_OPS => KeyOperationsParameter::class, |
|
81 | - self::P_ALG => AlgorithmParameter::class, |
|
82 | - self::P_KID => KeyIDParameter::class, |
|
83 | - self::P_X5U => X509URLParameter::class, |
|
84 | - self::P_X5C => X509CertificateChainParameter::class, |
|
85 | - self::P_X5T => X509CertificateSHA1ThumbprintParameter::class, |
|
86 | - self::P_X5TS256 => X509CertificateSHA256ThumbprintParameter::class, |
|
87 | - self::P_CRV => CurveParameter::class, |
|
88 | - self::P_X => XCoordinateParameter::class, |
|
89 | - self::P_Y => YCoordinateParameter::class, |
|
90 | - self::P_N => ModulusParameter::class, |
|
91 | - self::P_E => ExponentParameter::class, |
|
92 | - self::P_P => FirstPrimeFactorParameter::class, |
|
93 | - self::P_Q => SecondPrimeFactorParameter::class, |
|
94 | - self::P_DP => FirstFactorCRTExponentParameter::class, |
|
95 | - self::P_DQ => SecondFactorCRTExponentParameter::class, |
|
96 | - self::P_QI => FirstCRTCoefficientParameter::class, |
|
97 | - self::P_OTH => OtherPrimesInfoParameter::class, |
|
98 | - self::P_K => KeyValueParameter::class, |
|
99 | - ]; |
|
67 | + /** |
|
68 | + * Mapping from registered JWK parameter name to class name. |
|
69 | + * |
|
70 | + * Note that ECC private key and RSA private key cannot be mapped since |
|
71 | + * they share the same parameter name 'd'. |
|
72 | + * |
|
73 | + * @internal |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + const MAP_NAME_TO_CLASS = [ |
|
78 | + self::P_KTY => KeyTypeParameter::class, |
|
79 | + self::P_USE => PublicKeyUseParameter::class, |
|
80 | + self::P_KEY_OPS => KeyOperationsParameter::class, |
|
81 | + self::P_ALG => AlgorithmParameter::class, |
|
82 | + self::P_KID => KeyIDParameter::class, |
|
83 | + self::P_X5U => X509URLParameter::class, |
|
84 | + self::P_X5C => X509CertificateChainParameter::class, |
|
85 | + self::P_X5T => X509CertificateSHA1ThumbprintParameter::class, |
|
86 | + self::P_X5TS256 => X509CertificateSHA256ThumbprintParameter::class, |
|
87 | + self::P_CRV => CurveParameter::class, |
|
88 | + self::P_X => XCoordinateParameter::class, |
|
89 | + self::P_Y => YCoordinateParameter::class, |
|
90 | + self::P_N => ModulusParameter::class, |
|
91 | + self::P_E => ExponentParameter::class, |
|
92 | + self::P_P => FirstPrimeFactorParameter::class, |
|
93 | + self::P_Q => SecondPrimeFactorParameter::class, |
|
94 | + self::P_DP => FirstFactorCRTExponentParameter::class, |
|
95 | + self::P_DQ => SecondFactorCRTExponentParameter::class, |
|
96 | + self::P_QI => FirstCRTCoefficientParameter::class, |
|
97 | + self::P_OTH => OtherPrimesInfoParameter::class, |
|
98 | + self::P_K => KeyValueParameter::class, |
|
99 | + ]; |
|
100 | 100 | |
101 | - /** |
|
102 | - * Constructor. |
|
103 | - * |
|
104 | - * @param string $name Parameter name |
|
105 | - * @param mixed $value Parameter value |
|
106 | - */ |
|
107 | - public function __construct(string $name, $value) |
|
108 | - { |
|
109 | - $this->_name = $name; |
|
110 | - $this->_value = $value; |
|
111 | - } |
|
101 | + /** |
|
102 | + * Constructor. |
|
103 | + * |
|
104 | + * @param string $name Parameter name |
|
105 | + * @param mixed $value Parameter value |
|
106 | + */ |
|
107 | + public function __construct(string $name, $value) |
|
108 | + { |
|
109 | + $this->_name = $name; |
|
110 | + $this->_value = $value; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Initialize from a name and a value. |
|
115 | - * |
|
116 | - * Returns a parameter specific object if one is implemented. |
|
117 | - * |
|
118 | - * @param string $name Parameter name |
|
119 | - * @param mixed $value Parameter value |
|
120 | - * |
|
121 | - * @return self |
|
122 | - */ |
|
123 | - public static function fromNameAndValue(string $name, $value): self |
|
124 | - { |
|
125 | - if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) { |
|
126 | - $cls = self::MAP_NAME_TO_CLASS[$name]; |
|
127 | - return $cls::fromJSONValue($value); |
|
128 | - } |
|
129 | - return new self($name, $value); |
|
130 | - } |
|
113 | + /** |
|
114 | + * Initialize from a name and a value. |
|
115 | + * |
|
116 | + * Returns a parameter specific object if one is implemented. |
|
117 | + * |
|
118 | + * @param string $name Parameter name |
|
119 | + * @param mixed $value Parameter value |
|
120 | + * |
|
121 | + * @return self |
|
122 | + */ |
|
123 | + public static function fromNameAndValue(string $name, $value): self |
|
124 | + { |
|
125 | + if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) { |
|
126 | + $cls = self::MAP_NAME_TO_CLASS[$name]; |
|
127 | + return $cls::fromJSONValue($value); |
|
128 | + } |
|
129 | + return new self($name, $value); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Initialize from a JSON value. |
|
134 | - * |
|
135 | - * @param mixed $value |
|
136 | - * |
|
137 | - * @return JWKParameter |
|
138 | - */ |
|
139 | - public static function fromJSONValue($value): Parameter |
|
140 | - { |
|
141 | - throw new \BadMethodCallException( |
|
142 | - __FUNCTION__ . ' must be implemented in a derived class.'); |
|
143 | - } |
|
132 | + /** |
|
133 | + * Initialize from a JSON value. |
|
134 | + * |
|
135 | + * @param mixed $value |
|
136 | + * |
|
137 | + * @return JWKParameter |
|
138 | + */ |
|
139 | + public static function fromJSONValue($value): Parameter |
|
140 | + { |
|
141 | + throw new \BadMethodCallException( |
|
142 | + __FUNCTION__ . ' must be implemented in a derived class.'); |
|
143 | + } |
|
144 | 144 | } |
@@ -13,117 +13,117 @@ |
||
13 | 13 | */ |
14 | 14 | class CurveParameter extends JWKParameter |
15 | 15 | { |
16 | - use StringParameterValue; |
|
16 | + use StringParameterValue; |
|
17 | 17 | |
18 | - /** |
|
19 | - * P-256 Curve. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - const CURVE_P256 = 'P-256'; |
|
18 | + /** |
|
19 | + * P-256 Curve. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + const CURVE_P256 = 'P-256'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * P-384 Curve. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - const CURVE_P384 = 'P-384'; |
|
25 | + /** |
|
26 | + * P-384 Curve. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + const CURVE_P384 = 'P-384'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * P-521 Curve. |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - const CURVE_P521 = 'P-521'; |
|
32 | + /** |
|
33 | + * P-521 Curve. |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + const CURVE_P521 = 'P-521'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Mapping from curve OID to curve name. |
|
41 | - * |
|
42 | - * @internal |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - const MAP_OID_TO_CURVE = [ |
|
47 | - '1.2.840.10045.3.1.7' => self::CURVE_P256, |
|
48 | - '1.3.132.0.34' => self::CURVE_P384, |
|
49 | - '1.3.132.0.35' => self::CURVE_P521, |
|
50 | - ]; |
|
39 | + /** |
|
40 | + * Mapping from curve OID to curve name. |
|
41 | + * |
|
42 | + * @internal |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + const MAP_OID_TO_CURVE = [ |
|
47 | + '1.2.840.10045.3.1.7' => self::CURVE_P256, |
|
48 | + '1.3.132.0.34' => self::CURVE_P384, |
|
49 | + '1.3.132.0.35' => self::CURVE_P521, |
|
50 | + ]; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Mapping from curve name to bit size. |
|
54 | - * |
|
55 | - * @internal |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - const MAP_CURVE_TO_SIZE = [ |
|
60 | - self::CURVE_P256 => 256, |
|
61 | - self::CURVE_P384 => 384, |
|
62 | - self::CURVE_P521 => 521, |
|
63 | - ]; |
|
52 | + /** |
|
53 | + * Mapping from curve name to bit size. |
|
54 | + * |
|
55 | + * @internal |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + const MAP_CURVE_TO_SIZE = [ |
|
60 | + self::CURVE_P256 => 256, |
|
61 | + self::CURVE_P384 => 384, |
|
62 | + self::CURVE_P521 => 521, |
|
63 | + ]; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Constructor. |
|
67 | - * |
|
68 | - * @param string $curve Curve name |
|
69 | - */ |
|
70 | - public function __construct(string $curve) |
|
71 | - { |
|
72 | - parent::__construct(self::PARAM_CURVE, $curve); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Constructor. |
|
67 | + * |
|
68 | + * @param string $curve Curve name |
|
69 | + */ |
|
70 | + public function __construct(string $curve) |
|
71 | + { |
|
72 | + parent::__construct(self::PARAM_CURVE, $curve); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Initialize from curve OID. |
|
77 | - * |
|
78 | - * @param string $oid Object identifier in dotted format |
|
79 | - * |
|
80 | - * @throws \UnexpectedValueException If the curve is not supported |
|
81 | - * |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public static function fromOID(string $oid): self |
|
85 | - { |
|
86 | - if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
87 | - throw new \UnexpectedValueException("OID {$oid} not supported."); |
|
88 | - } |
|
89 | - $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
90 | - return new self($curve); |
|
91 | - } |
|
75 | + /** |
|
76 | + * Initialize from curve OID. |
|
77 | + * |
|
78 | + * @param string $oid Object identifier in dotted format |
|
79 | + * |
|
80 | + * @throws \UnexpectedValueException If the curve is not supported |
|
81 | + * |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public static function fromOID(string $oid): self |
|
85 | + { |
|
86 | + if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
87 | + throw new \UnexpectedValueException("OID {$oid} not supported."); |
|
88 | + } |
|
89 | + $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
90 | + return new self($curve); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get key size in bits for the curve. |
|
95 | - * |
|
96 | - * @throws \UnexpectedValueException |
|
97 | - * |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function keySizeBits(): int |
|
101 | - { |
|
102 | - if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
103 | - throw new \UnexpectedValueException( |
|
104 | - 'Curve ' . $this->_value . ' not supported.'); |
|
105 | - } |
|
106 | - return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
107 | - } |
|
93 | + /** |
|
94 | + * Get key size in bits for the curve. |
|
95 | + * |
|
96 | + * @throws \UnexpectedValueException |
|
97 | + * |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function keySizeBits(): int |
|
101 | + { |
|
102 | + if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
103 | + throw new \UnexpectedValueException( |
|
104 | + 'Curve ' . $this->_value . ' not supported.'); |
|
105 | + } |
|
106 | + return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get the curve OID by curve name. |
|
111 | - * |
|
112 | - * @param string $name Curve parameter name |
|
113 | - * |
|
114 | - * @throws \UnexpectedValueException If the curve is not supported |
|
115 | - * |
|
116 | - * @return string OID in dotted format |
|
117 | - */ |
|
118 | - public static function nameToOID(string $name): string |
|
119 | - { |
|
120 | - static $reverseMap; |
|
121 | - if (!isset($reverseMap)) { |
|
122 | - $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
123 | - } |
|
124 | - if (!isset($reverseMap[$name])) { |
|
125 | - throw new \UnexpectedValueException("Curve {$name} not supported."); |
|
126 | - } |
|
127 | - return $reverseMap[$name]; |
|
128 | - } |
|
109 | + /** |
|
110 | + * Get the curve OID by curve name. |
|
111 | + * |
|
112 | + * @param string $name Curve parameter name |
|
113 | + * |
|
114 | + * @throws \UnexpectedValueException If the curve is not supported |
|
115 | + * |
|
116 | + * @return string OID in dotted format |
|
117 | + */ |
|
118 | + public static function nameToOID(string $name): string |
|
119 | + { |
|
120 | + static $reverseMap; |
|
121 | + if (!isset($reverseMap)) { |
|
122 | + $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
123 | + } |
|
124 | + if (!isset($reverseMap[$name])) { |
|
125 | + throw new \UnexpectedValueException("Curve {$name} not supported."); |
|
126 | + } |
|
127 | + return $reverseMap[$name]; |
|
128 | + } |
|
129 | 129 | } |
@@ -11,594 +11,594 @@ |
||
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 | } |