@@ -13,52 +13,52 @@ |
||
13 | 13 | */ |
14 | 14 | class CriticalParameter extends JWTParameter |
15 | 15 | { |
16 | - use ArrayParameterValue; |
|
16 | + use ArrayParameterValue; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Constructor. |
|
20 | - * |
|
21 | - * @param string ...$names |
|
22 | - */ |
|
23 | - public function __construct(string ...$names) |
|
24 | - { |
|
25 | - parent::__construct(self::PARAM_CRITICAL, $names); |
|
26 | - } |
|
18 | + /** |
|
19 | + * Constructor. |
|
20 | + * |
|
21 | + * @param string ...$names |
|
22 | + */ |
|
23 | + public function __construct(string ...$names) |
|
24 | + { |
|
25 | + parent::__construct(self::PARAM_CRITICAL, $names); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Get self with parameter name added. |
|
30 | - * |
|
31 | - * @param string $name |
|
32 | - * |
|
33 | - * @return self |
|
34 | - */ |
|
35 | - public function withParamName(string $name): self |
|
36 | - { |
|
37 | - $obj = clone $this; |
|
38 | - $obj->_value[] = $name; |
|
39 | - $obj->_value = array_values(array_unique($obj->_value)); |
|
40 | - return $obj; |
|
41 | - } |
|
28 | + /** |
|
29 | + * Get self with parameter name added. |
|
30 | + * |
|
31 | + * @param string $name |
|
32 | + * |
|
33 | + * @return self |
|
34 | + */ |
|
35 | + public function withParamName(string $name): self |
|
36 | + { |
|
37 | + $obj = clone $this; |
|
38 | + $obj->_value[] = $name; |
|
39 | + $obj->_value = array_values(array_unique($obj->_value)); |
|
40 | + return $obj; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Check whether given parameter name is critical. |
|
45 | - * |
|
46 | - * @param string $name |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function has(string $name): bool |
|
51 | - { |
|
52 | - return false !== array_search($name, $this->_value); |
|
53 | - } |
|
43 | + /** |
|
44 | + * Check whether given parameter name is critical. |
|
45 | + * |
|
46 | + * @param string $name |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function has(string $name): bool |
|
51 | + { |
|
52 | + return false !== array_search($name, $this->_value); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get critical header parameter names. |
|
57 | - * |
|
58 | - * @return string[] |
|
59 | - */ |
|
60 | - public function names(): array |
|
61 | - { |
|
62 | - return $this->_value; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get critical header parameter names. |
|
57 | + * |
|
58 | + * @return string[] |
|
59 | + */ |
|
60 | + public function names(): array |
|
61 | + { |
|
62 | + return $this->_value; |
|
63 | + } |
|
64 | 64 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Parameter; |
6 | 6 |
@@ -26,445 +26,445 @@ |
||
26 | 26 | */ |
27 | 27 | class JWT |
28 | 28 | { |
29 | - /** |
|
30 | - * Type identifier for the signed JWT. |
|
31 | - * |
|
32 | - * @internal |
|
33 | - * |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - const TYPE_JWS = 0; |
|
29 | + /** |
|
30 | + * Type identifier for the signed JWT. |
|
31 | + * |
|
32 | + * @internal |
|
33 | + * |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + const TYPE_JWS = 0; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Type identifier for the encrypted JWT. |
|
40 | - * |
|
41 | - * @internal |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - const TYPE_JWE = 1; |
|
38 | + /** |
|
39 | + * Type identifier for the encrypted JWT. |
|
40 | + * |
|
41 | + * @internal |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + const TYPE_JWE = 1; |
|
46 | 46 | |
47 | - /** |
|
48 | - * JWT parts. |
|
49 | - * |
|
50 | - * @var string[] |
|
51 | - */ |
|
52 | - protected $_parts; |
|
47 | + /** |
|
48 | + * JWT parts. |
|
49 | + * |
|
50 | + * @var string[] |
|
51 | + */ |
|
52 | + protected $_parts; |
|
53 | 53 | |
54 | - /** |
|
55 | - * JWT type. |
|
56 | - * |
|
57 | - * @var int |
|
58 | - */ |
|
59 | - protected $_type; |
|
54 | + /** |
|
55 | + * JWT type. |
|
56 | + * |
|
57 | + * @var int |
|
58 | + */ |
|
59 | + protected $_type; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Constructor. |
|
63 | - * |
|
64 | - * @param string $token JWT string |
|
65 | - * |
|
66 | - * @throws \UnexpectedValueException |
|
67 | - */ |
|
68 | - public function __construct(string $token) |
|
69 | - { |
|
70 | - $this->_parts = explode('.', $token); |
|
71 | - switch (count($this->_parts)) { |
|
72 | - case 3: |
|
73 | - $this->_type = self::TYPE_JWS; |
|
74 | - break; |
|
75 | - case 5: |
|
76 | - $this->_type = self::TYPE_JWE; |
|
77 | - break; |
|
78 | - default: |
|
79 | - throw new \UnexpectedValueException('Not a JWT token.'); |
|
80 | - } |
|
81 | - } |
|
61 | + /** |
|
62 | + * Constructor. |
|
63 | + * |
|
64 | + * @param string $token JWT string |
|
65 | + * |
|
66 | + * @throws \UnexpectedValueException |
|
67 | + */ |
|
68 | + public function __construct(string $token) |
|
69 | + { |
|
70 | + $this->_parts = explode('.', $token); |
|
71 | + switch (count($this->_parts)) { |
|
72 | + case 3: |
|
73 | + $this->_type = self::TYPE_JWS; |
|
74 | + break; |
|
75 | + case 5: |
|
76 | + $this->_type = self::TYPE_JWE; |
|
77 | + break; |
|
78 | + default: |
|
79 | + throw new \UnexpectedValueException('Not a JWT token.'); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Convert JWT to string. |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function __toString(): string |
|
89 | - { |
|
90 | - return $this->token(); |
|
91 | - } |
|
83 | + /** |
|
84 | + * Convert JWT to string. |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function __toString(): string |
|
89 | + { |
|
90 | + return $this->token(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Convert claims set to an unsecured JWT. |
|
95 | - * |
|
96 | - * Unsecured JWT is not signed nor encrypted neither integrity protected, |
|
97 | - * and should thus be handled with care! |
|
98 | - * |
|
99 | - * @see https://tools.ietf.org/html/rfc7519#section-6 |
|
100 | - * |
|
101 | - * @param Claims $claims Claims set |
|
102 | - * @param null|Header $header Optional header |
|
103 | - * |
|
104 | - * @throws \RuntimeException For generic errors |
|
105 | - * |
|
106 | - * @return self |
|
107 | - */ |
|
108 | - public static function unsecuredFromClaims(Claims $claims, |
|
109 | - ?Header $header = null): self |
|
110 | - { |
|
111 | - return self::signedFromClaims($claims, new NoneAlgorithm(), $header); |
|
112 | - } |
|
93 | + /** |
|
94 | + * Convert claims set to an unsecured JWT. |
|
95 | + * |
|
96 | + * Unsecured JWT is not signed nor encrypted neither integrity protected, |
|
97 | + * and should thus be handled with care! |
|
98 | + * |
|
99 | + * @see https://tools.ietf.org/html/rfc7519#section-6 |
|
100 | + * |
|
101 | + * @param Claims $claims Claims set |
|
102 | + * @param null|Header $header Optional header |
|
103 | + * |
|
104 | + * @throws \RuntimeException For generic errors |
|
105 | + * |
|
106 | + * @return self |
|
107 | + */ |
|
108 | + public static function unsecuredFromClaims(Claims $claims, |
|
109 | + ?Header $header = null): self |
|
110 | + { |
|
111 | + return self::signedFromClaims($claims, new NoneAlgorithm(), $header); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Convert claims set to a signed JWS token. |
|
116 | - * |
|
117 | - * @param Claims $claims Claims set |
|
118 | - * @param SignatureAlgorithm $algo Signature algorithm |
|
119 | - * @param null|Header $header Optional header |
|
120 | - * |
|
121 | - * @throws \RuntimeException For generic errors |
|
122 | - * |
|
123 | - * @return self |
|
124 | - */ |
|
125 | - public static function signedFromClaims(Claims $claims, |
|
126 | - SignatureAlgorithm $algo, ?Header $header = null): self |
|
127 | - { |
|
128 | - $payload = $claims->toJSON(); |
|
129 | - $jws = JWS::sign($payload, $algo, $header); |
|
130 | - return new self($jws->toCompact()); |
|
131 | - } |
|
114 | + /** |
|
115 | + * Convert claims set to a signed JWS token. |
|
116 | + * |
|
117 | + * @param Claims $claims Claims set |
|
118 | + * @param SignatureAlgorithm $algo Signature algorithm |
|
119 | + * @param null|Header $header Optional header |
|
120 | + * |
|
121 | + * @throws \RuntimeException For generic errors |
|
122 | + * |
|
123 | + * @return self |
|
124 | + */ |
|
125 | + public static function signedFromClaims(Claims $claims, |
|
126 | + SignatureAlgorithm $algo, ?Header $header = null): self |
|
127 | + { |
|
128 | + $payload = $claims->toJSON(); |
|
129 | + $jws = JWS::sign($payload, $algo, $header); |
|
130 | + return new self($jws->toCompact()); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Convert claims set to an encrypted JWE token. |
|
135 | - * |
|
136 | - * @param Claims $claims Claims set |
|
137 | - * @param KeyManagementAlgorithm $key_algo Key management algorithm |
|
138 | - * @param ContentEncryptionAlgorithm $enc_algo Content encryption algorithm |
|
139 | - * @param null|CompressionAlgorithm $zip_algo Optional compression algorithm |
|
140 | - * @param null|Header $header Optional header |
|
141 | - * |
|
142 | - * @throws \RuntimeException For generic errors |
|
143 | - * |
|
144 | - * @return self |
|
145 | - */ |
|
146 | - public static function encryptedFromClaims(Claims $claims, |
|
147 | - KeyManagementAlgorithm $key_algo, ContentEncryptionAlgorithm $enc_algo, |
|
148 | - ?CompressionAlgorithm $zip_algo = null, ?Header $header = null): self |
|
149 | - { |
|
150 | - $payload = $claims->toJSON(); |
|
151 | - $jwe = JWE::encrypt($payload, $key_algo, $enc_algo, $zip_algo, $header); |
|
152 | - return new self($jwe->toCompact()); |
|
153 | - } |
|
133 | + /** |
|
134 | + * Convert claims set to an encrypted JWE token. |
|
135 | + * |
|
136 | + * @param Claims $claims Claims set |
|
137 | + * @param KeyManagementAlgorithm $key_algo Key management algorithm |
|
138 | + * @param ContentEncryptionAlgorithm $enc_algo Content encryption algorithm |
|
139 | + * @param null|CompressionAlgorithm $zip_algo Optional compression algorithm |
|
140 | + * @param null|Header $header Optional header |
|
141 | + * |
|
142 | + * @throws \RuntimeException For generic errors |
|
143 | + * |
|
144 | + * @return self |
|
145 | + */ |
|
146 | + public static function encryptedFromClaims(Claims $claims, |
|
147 | + KeyManagementAlgorithm $key_algo, ContentEncryptionAlgorithm $enc_algo, |
|
148 | + ?CompressionAlgorithm $zip_algo = null, ?Header $header = null): self |
|
149 | + { |
|
150 | + $payload = $claims->toJSON(); |
|
151 | + $jwe = JWE::encrypt($payload, $key_algo, $enc_algo, $zip_algo, $header); |
|
152 | + return new self($jwe->toCompact()); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Get claims from the JWT. |
|
157 | - * |
|
158 | - * Claims shall be validated according to given validation context. |
|
159 | - * Validation context must contain all the necessary keys for the signature |
|
160 | - * validation and/or content decryption. |
|
161 | - * |
|
162 | - * If validation context contains only one key, it shall be used explicitly. |
|
163 | - * If multiple keys are provided, they must contain a JWK ID parameter for |
|
164 | - * the key identification. |
|
165 | - * |
|
166 | - * @param ValidationContext $ctx |
|
167 | - * |
|
168 | - * @throws ValidationException if signature is invalid, or decryption fails, |
|
169 | - * or claims validation fails |
|
170 | - * @throws \RuntimeException For generic errors |
|
171 | - * |
|
172 | - * @return Claims |
|
173 | - */ |
|
174 | - public function claims(ValidationContext $ctx): Claims |
|
175 | - { |
|
176 | - // check signature or decrypt depending on the JWT type. |
|
177 | - if ($this->isJWS()) { |
|
178 | - $payload = self::_validatedPayloadFromJWS($this->JWS(), $ctx); |
|
179 | - } else { |
|
180 | - $payload = self::_validatedPayloadFromJWE($this->JWE(), $ctx); |
|
181 | - } |
|
182 | - // if JWT contains a nested token |
|
183 | - if ($this->isNested()) { |
|
184 | - return $this->_claimsFromNestedPayload($payload, $ctx); |
|
185 | - } |
|
186 | - // decode claims and validate |
|
187 | - $claims = Claims::fromJSON($payload); |
|
188 | - $ctx->validate($claims); |
|
189 | - return $claims; |
|
190 | - } |
|
155 | + /** |
|
156 | + * Get claims from the JWT. |
|
157 | + * |
|
158 | + * Claims shall be validated according to given validation context. |
|
159 | + * Validation context must contain all the necessary keys for the signature |
|
160 | + * validation and/or content decryption. |
|
161 | + * |
|
162 | + * If validation context contains only one key, it shall be used explicitly. |
|
163 | + * If multiple keys are provided, they must contain a JWK ID parameter for |
|
164 | + * the key identification. |
|
165 | + * |
|
166 | + * @param ValidationContext $ctx |
|
167 | + * |
|
168 | + * @throws ValidationException if signature is invalid, or decryption fails, |
|
169 | + * or claims validation fails |
|
170 | + * @throws \RuntimeException For generic errors |
|
171 | + * |
|
172 | + * @return Claims |
|
173 | + */ |
|
174 | + public function claims(ValidationContext $ctx): Claims |
|
175 | + { |
|
176 | + // check signature or decrypt depending on the JWT type. |
|
177 | + if ($this->isJWS()) { |
|
178 | + $payload = self::_validatedPayloadFromJWS($this->JWS(), $ctx); |
|
179 | + } else { |
|
180 | + $payload = self::_validatedPayloadFromJWE($this->JWE(), $ctx); |
|
181 | + } |
|
182 | + // if JWT contains a nested token |
|
183 | + if ($this->isNested()) { |
|
184 | + return $this->_claimsFromNestedPayload($payload, $ctx); |
|
185 | + } |
|
186 | + // decode claims and validate |
|
187 | + $claims = Claims::fromJSON($payload); |
|
188 | + $ctx->validate($claims); |
|
189 | + return $claims; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Sign self producing a nested JWT. |
|
194 | - * |
|
195 | - * Note that if JWT is to be signed and encrypted, it should be done in |
|
196 | - * sign-then-encrypt order. Please refer to links for security information. |
|
197 | - * |
|
198 | - * @see https://tools.ietf.org/html/rfc7519#section-11.2 |
|
199 | - * |
|
200 | - * @param SignatureAlgorithm $algo Signature algorithm |
|
201 | - * @param null|Header $header Optional header |
|
202 | - * |
|
203 | - * @throws \RuntimeException For generic errors |
|
204 | - * |
|
205 | - * @return self |
|
206 | - */ |
|
207 | - public function signNested(SignatureAlgorithm $algo, ?Header $header = null): self |
|
208 | - { |
|
209 | - if (!isset($header)) { |
|
210 | - $header = new Header(); |
|
211 | - } |
|
212 | - // add JWT content type parameter |
|
213 | - $header = $header->withParameters( |
|
214 | - new ContentTypeParameter(ContentTypeParameter::TYPE_JWT)); |
|
215 | - $jws = JWS::sign($this->token(), $algo, $header); |
|
216 | - return new self($jws->toCompact()); |
|
217 | - } |
|
192 | + /** |
|
193 | + * Sign self producing a nested JWT. |
|
194 | + * |
|
195 | + * Note that if JWT is to be signed and encrypted, it should be done in |
|
196 | + * sign-then-encrypt order. Please refer to links for security information. |
|
197 | + * |
|
198 | + * @see https://tools.ietf.org/html/rfc7519#section-11.2 |
|
199 | + * |
|
200 | + * @param SignatureAlgorithm $algo Signature algorithm |
|
201 | + * @param null|Header $header Optional header |
|
202 | + * |
|
203 | + * @throws \RuntimeException For generic errors |
|
204 | + * |
|
205 | + * @return self |
|
206 | + */ |
|
207 | + public function signNested(SignatureAlgorithm $algo, ?Header $header = null): self |
|
208 | + { |
|
209 | + if (!isset($header)) { |
|
210 | + $header = new Header(); |
|
211 | + } |
|
212 | + // add JWT content type parameter |
|
213 | + $header = $header->withParameters( |
|
214 | + new ContentTypeParameter(ContentTypeParameter::TYPE_JWT)); |
|
215 | + $jws = JWS::sign($this->token(), $algo, $header); |
|
216 | + return new self($jws->toCompact()); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Encrypt self producing a nested JWT. |
|
221 | - * |
|
222 | - * This JWT should be a JWS, that is, the order of nesting should be |
|
223 | - * sign-then-encrypt. |
|
224 | - * |
|
225 | - * @see https://tools.ietf.org/html/rfc7519#section-11.2 |
|
226 | - * |
|
227 | - * @param KeyManagementAlgorithm $key_algo Key management algorithm |
|
228 | - * @param ContentEncryptionAlgorithm $enc_algo Content encryption algorithm |
|
229 | - * @param null|CompressionAlgorithm $zip_algo Optional compression algorithm |
|
230 | - * @param null|Header $header Optional header |
|
231 | - * |
|
232 | - * @throws \RuntimeException For generic errors |
|
233 | - * |
|
234 | - * @return self |
|
235 | - */ |
|
236 | - public function encryptNested(KeyManagementAlgorithm $key_algo, |
|
237 | - ContentEncryptionAlgorithm $enc_algo, |
|
238 | - ?CompressionAlgorithm $zip_algo = null, ?Header $header = null): self |
|
239 | - { |
|
240 | - if (!isset($header)) { |
|
241 | - $header = new Header(); |
|
242 | - } |
|
243 | - // add JWT content type parameter |
|
244 | - $header = $header->withParameters( |
|
245 | - new ContentTypeParameter(ContentTypeParameter::TYPE_JWT)); |
|
246 | - $jwe = JWE::encrypt($this->token(), $key_algo, $enc_algo, $zip_algo, |
|
247 | - $header); |
|
248 | - return new self($jwe->toCompact()); |
|
249 | - } |
|
219 | + /** |
|
220 | + * Encrypt self producing a nested JWT. |
|
221 | + * |
|
222 | + * This JWT should be a JWS, that is, the order of nesting should be |
|
223 | + * sign-then-encrypt. |
|
224 | + * |
|
225 | + * @see https://tools.ietf.org/html/rfc7519#section-11.2 |
|
226 | + * |
|
227 | + * @param KeyManagementAlgorithm $key_algo Key management algorithm |
|
228 | + * @param ContentEncryptionAlgorithm $enc_algo Content encryption algorithm |
|
229 | + * @param null|CompressionAlgorithm $zip_algo Optional compression algorithm |
|
230 | + * @param null|Header $header Optional header |
|
231 | + * |
|
232 | + * @throws \RuntimeException For generic errors |
|
233 | + * |
|
234 | + * @return self |
|
235 | + */ |
|
236 | + public function encryptNested(KeyManagementAlgorithm $key_algo, |
|
237 | + ContentEncryptionAlgorithm $enc_algo, |
|
238 | + ?CompressionAlgorithm $zip_algo = null, ?Header $header = null): self |
|
239 | + { |
|
240 | + if (!isset($header)) { |
|
241 | + $header = new Header(); |
|
242 | + } |
|
243 | + // add JWT content type parameter |
|
244 | + $header = $header->withParameters( |
|
245 | + new ContentTypeParameter(ContentTypeParameter::TYPE_JWT)); |
|
246 | + $jwe = JWE::encrypt($this->token(), $key_algo, $enc_algo, $zip_algo, |
|
247 | + $header); |
|
248 | + return new self($jwe->toCompact()); |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * Whether JWT is a JWS. |
|
253 | - * |
|
254 | - * @return bool |
|
255 | - */ |
|
256 | - public function isJWS(): bool |
|
257 | - { |
|
258 | - return self::TYPE_JWS === $this->_type; |
|
259 | - } |
|
251 | + /** |
|
252 | + * Whether JWT is a JWS. |
|
253 | + * |
|
254 | + * @return bool |
|
255 | + */ |
|
256 | + public function isJWS(): bool |
|
257 | + { |
|
258 | + return self::TYPE_JWS === $this->_type; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Get JWT as a JWS. |
|
263 | - * |
|
264 | - * @throws \LogicException |
|
265 | - * |
|
266 | - * @return JWS |
|
267 | - */ |
|
268 | - public function JWS(): JWS |
|
269 | - { |
|
270 | - if (!$this->isJWS()) { |
|
271 | - throw new \LogicException('Not a JWS.'); |
|
272 | - } |
|
273 | - return JWS::fromParts($this->_parts); |
|
274 | - } |
|
261 | + /** |
|
262 | + * Get JWT as a JWS. |
|
263 | + * |
|
264 | + * @throws \LogicException |
|
265 | + * |
|
266 | + * @return JWS |
|
267 | + */ |
|
268 | + public function JWS(): JWS |
|
269 | + { |
|
270 | + if (!$this->isJWS()) { |
|
271 | + throw new \LogicException('Not a JWS.'); |
|
272 | + } |
|
273 | + return JWS::fromParts($this->_parts); |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Whether JWT is a JWE. |
|
278 | - * |
|
279 | - * @return bool |
|
280 | - */ |
|
281 | - public function isJWE(): bool |
|
282 | - { |
|
283 | - return self::TYPE_JWE === $this->_type; |
|
284 | - } |
|
276 | + /** |
|
277 | + * Whether JWT is a JWE. |
|
278 | + * |
|
279 | + * @return bool |
|
280 | + */ |
|
281 | + public function isJWE(): bool |
|
282 | + { |
|
283 | + return self::TYPE_JWE === $this->_type; |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * Get JWT as a JWE. |
|
288 | - * |
|
289 | - * @throws \LogicException |
|
290 | - * |
|
291 | - * @return JWE |
|
292 | - */ |
|
293 | - public function JWE(): JWE |
|
294 | - { |
|
295 | - if (!$this->isJWE()) { |
|
296 | - throw new \LogicException('Not a JWE.'); |
|
297 | - } |
|
298 | - return JWE::fromParts($this->_parts); |
|
299 | - } |
|
286 | + /** |
|
287 | + * Get JWT as a JWE. |
|
288 | + * |
|
289 | + * @throws \LogicException |
|
290 | + * |
|
291 | + * @return JWE |
|
292 | + */ |
|
293 | + public function JWE(): JWE |
|
294 | + { |
|
295 | + if (!$this->isJWE()) { |
|
296 | + throw new \LogicException('Not a JWE.'); |
|
297 | + } |
|
298 | + return JWE::fromParts($this->_parts); |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Check whether JWT contains another nested JWT. |
|
303 | - * |
|
304 | - * @return bool |
|
305 | - */ |
|
306 | - public function isNested(): bool |
|
307 | - { |
|
308 | - $header = $this->header(); |
|
309 | - if (!$header->hasContentType()) { |
|
310 | - return false; |
|
311 | - } |
|
312 | - $cty = $header->contentType()->value(); |
|
313 | - if (ContentTypeParameter::TYPE_JWT !== $cty) { |
|
314 | - return false; |
|
315 | - } |
|
316 | - return true; |
|
317 | - } |
|
301 | + /** |
|
302 | + * Check whether JWT contains another nested JWT. |
|
303 | + * |
|
304 | + * @return bool |
|
305 | + */ |
|
306 | + public function isNested(): bool |
|
307 | + { |
|
308 | + $header = $this->header(); |
|
309 | + if (!$header->hasContentType()) { |
|
310 | + return false; |
|
311 | + } |
|
312 | + $cty = $header->contentType()->value(); |
|
313 | + if (ContentTypeParameter::TYPE_JWT !== $cty) { |
|
314 | + return false; |
|
315 | + } |
|
316 | + return true; |
|
317 | + } |
|
318 | 318 | |
319 | - /** |
|
320 | - * Check whether JWT is unsecured, that is, it's neither integrity protected |
|
321 | - * nor encrypted. |
|
322 | - * |
|
323 | - * @return bool |
|
324 | - */ |
|
325 | - public function isUnsecured(): bool |
|
326 | - { |
|
327 | - // encrypted JWT shall be considered secure |
|
328 | - if ($this->isJWE()) { |
|
329 | - return false; |
|
330 | - } |
|
331 | - // check whether JWS is unsecured |
|
332 | - return $this->JWS()->isUnsecured(); |
|
333 | - } |
|
319 | + /** |
|
320 | + * Check whether JWT is unsecured, that is, it's neither integrity protected |
|
321 | + * nor encrypted. |
|
322 | + * |
|
323 | + * @return bool |
|
324 | + */ |
|
325 | + public function isUnsecured(): bool |
|
326 | + { |
|
327 | + // encrypted JWT shall be considered secure |
|
328 | + if ($this->isJWE()) { |
|
329 | + return false; |
|
330 | + } |
|
331 | + // check whether JWS is unsecured |
|
332 | + return $this->JWS()->isUnsecured(); |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * Get JWT header. |
|
337 | - * |
|
338 | - * @return JOSE |
|
339 | - */ |
|
340 | - public function header(): JOSE |
|
341 | - { |
|
342 | - $header = Header::fromJSON(Base64::urlDecode($this->_parts[0])); |
|
343 | - return new JOSE($header); |
|
344 | - } |
|
335 | + /** |
|
336 | + * Get JWT header. |
|
337 | + * |
|
338 | + * @return JOSE |
|
339 | + */ |
|
340 | + public function header(): JOSE |
|
341 | + { |
|
342 | + $header = Header::fromJSON(Base64::urlDecode($this->_parts[0])); |
|
343 | + return new JOSE($header); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * Get JWT as a string. |
|
348 | - * |
|
349 | - * @return string |
|
350 | - */ |
|
351 | - public function token(): string |
|
352 | - { |
|
353 | - return implode('.', $this->_parts); |
|
354 | - } |
|
346 | + /** |
|
347 | + * Get JWT as a string. |
|
348 | + * |
|
349 | + * @return string |
|
350 | + */ |
|
351 | + public function token(): string |
|
352 | + { |
|
353 | + return implode('.', $this->_parts); |
|
354 | + } |
|
355 | 355 | |
356 | - /** |
|
357 | - * Get claims from a nested payload. |
|
358 | - * |
|
359 | - * @param string $payload JWT payload |
|
360 | - * @param ValidationContext $ctx Validation context |
|
361 | - * |
|
362 | - * @return Claims |
|
363 | - */ |
|
364 | - private function _claimsFromNestedPayload(string $payload, |
|
365 | - ValidationContext $ctx): Claims |
|
366 | - { |
|
367 | - $jwt = new JWT($payload); |
|
368 | - // if this token secured, allow nested tokens to be unsecured. |
|
369 | - if (!$this->isUnsecured()) { |
|
370 | - $ctx = $ctx->withUnsecuredAllowed(true); |
|
371 | - } |
|
372 | - return $jwt->claims($ctx); |
|
373 | - } |
|
356 | + /** |
|
357 | + * Get claims from a nested payload. |
|
358 | + * |
|
359 | + * @param string $payload JWT payload |
|
360 | + * @param ValidationContext $ctx Validation context |
|
361 | + * |
|
362 | + * @return Claims |
|
363 | + */ |
|
364 | + private function _claimsFromNestedPayload(string $payload, |
|
365 | + ValidationContext $ctx): Claims |
|
366 | + { |
|
367 | + $jwt = new JWT($payload); |
|
368 | + // if this token secured, allow nested tokens to be unsecured. |
|
369 | + if (!$this->isUnsecured()) { |
|
370 | + $ctx = $ctx->withUnsecuredAllowed(true); |
|
371 | + } |
|
372 | + return $jwt->claims($ctx); |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Get validated payload from JWS. |
|
377 | - * |
|
378 | - * @param JWS $jws JWS |
|
379 | - * @param ValidationContext $ctx Validation context |
|
380 | - * |
|
381 | - * @throws ValidationException If signature validation fails |
|
382 | - * |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - private static function _validatedPayloadFromJWS(JWS $jws, |
|
386 | - ValidationContext $ctx): string |
|
387 | - { |
|
388 | - // if JWS is unsecured |
|
389 | - if ($jws->isUnsecured()) { |
|
390 | - return self::_validatedPayloadFromUnsecuredJWS($jws, $ctx); |
|
391 | - } |
|
392 | - return self::_validatedPayloadFromSignedJWS($jws, $ctx->keys()); |
|
393 | - } |
|
375 | + /** |
|
376 | + * Get validated payload from JWS. |
|
377 | + * |
|
378 | + * @param JWS $jws JWS |
|
379 | + * @param ValidationContext $ctx Validation context |
|
380 | + * |
|
381 | + * @throws ValidationException If signature validation fails |
|
382 | + * |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + private static function _validatedPayloadFromJWS(JWS $jws, |
|
386 | + ValidationContext $ctx): string |
|
387 | + { |
|
388 | + // if JWS is unsecured |
|
389 | + if ($jws->isUnsecured()) { |
|
390 | + return self::_validatedPayloadFromUnsecuredJWS($jws, $ctx); |
|
391 | + } |
|
392 | + return self::_validatedPayloadFromSignedJWS($jws, $ctx->keys()); |
|
393 | + } |
|
394 | 394 | |
395 | - /** |
|
396 | - * Get validated payload from an unsecured JWS. |
|
397 | - * |
|
398 | - * @param JWS $jws JWS |
|
399 | - * @param ValidationContext $ctx Validation context |
|
400 | - * |
|
401 | - * @throws ValidationException If unsecured JWT's are not allowed, or JWS |
|
402 | - * token is malformed |
|
403 | - * |
|
404 | - * @return string |
|
405 | - */ |
|
406 | - private static function _validatedPayloadFromUnsecuredJWS(JWS $jws, |
|
407 | - ValidationContext $ctx): string |
|
408 | - { |
|
409 | - if (!$ctx->isUnsecuredAllowed()) { |
|
410 | - throw new ValidationException('Unsecured JWS not allowed.'); |
|
411 | - } |
|
412 | - if (!$jws->validate(new NoneAlgorithm())) { |
|
413 | - throw new ValidationException('Malformed unsecured token.'); |
|
414 | - } |
|
415 | - return $jws->payload(); |
|
416 | - } |
|
395 | + /** |
|
396 | + * Get validated payload from an unsecured JWS. |
|
397 | + * |
|
398 | + * @param JWS $jws JWS |
|
399 | + * @param ValidationContext $ctx Validation context |
|
400 | + * |
|
401 | + * @throws ValidationException If unsecured JWT's are not allowed, or JWS |
|
402 | + * token is malformed |
|
403 | + * |
|
404 | + * @return string |
|
405 | + */ |
|
406 | + private static function _validatedPayloadFromUnsecuredJWS(JWS $jws, |
|
407 | + ValidationContext $ctx): string |
|
408 | + { |
|
409 | + if (!$ctx->isUnsecuredAllowed()) { |
|
410 | + throw new ValidationException('Unsecured JWS not allowed.'); |
|
411 | + } |
|
412 | + if (!$jws->validate(new NoneAlgorithm())) { |
|
413 | + throw new ValidationException('Malformed unsecured token.'); |
|
414 | + } |
|
415 | + return $jws->payload(); |
|
416 | + } |
|
417 | 417 | |
418 | - /** |
|
419 | - * Get validated payload from a signed JWS. |
|
420 | - * |
|
421 | - * @param JWS $jws JWS |
|
422 | - * @param JWKSet $keys Set of allowed keys for the signature validation |
|
423 | - * |
|
424 | - * @throws ValidationException If validation fails |
|
425 | - * |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - private static function _validatedPayloadFromSignedJWS(JWS $jws, JWKSet $keys): string |
|
429 | - { |
|
430 | - try { |
|
431 | - // explicitly defined key |
|
432 | - if (1 === count($keys)) { |
|
433 | - $valid = $jws->validateWithJWK($keys->first()); |
|
434 | - } else { |
|
435 | - $valid = $jws->validateWithJWKSet($keys); |
|
436 | - } |
|
437 | - } catch (\RuntimeException $e) { |
|
438 | - throw new ValidationException('JWS validation failed.', 0, $e); |
|
439 | - } |
|
440 | - if (!$valid) { |
|
441 | - throw new ValidationException('JWS signature is invalid.'); |
|
442 | - } |
|
443 | - return $jws->payload(); |
|
444 | - } |
|
418 | + /** |
|
419 | + * Get validated payload from a signed JWS. |
|
420 | + * |
|
421 | + * @param JWS $jws JWS |
|
422 | + * @param JWKSet $keys Set of allowed keys for the signature validation |
|
423 | + * |
|
424 | + * @throws ValidationException If validation fails |
|
425 | + * |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + private static function _validatedPayloadFromSignedJWS(JWS $jws, JWKSet $keys): string |
|
429 | + { |
|
430 | + try { |
|
431 | + // explicitly defined key |
|
432 | + if (1 === count($keys)) { |
|
433 | + $valid = $jws->validateWithJWK($keys->first()); |
|
434 | + } else { |
|
435 | + $valid = $jws->validateWithJWKSet($keys); |
|
436 | + } |
|
437 | + } catch (\RuntimeException $e) { |
|
438 | + throw new ValidationException('JWS validation failed.', 0, $e); |
|
439 | + } |
|
440 | + if (!$valid) { |
|
441 | + throw new ValidationException('JWS signature is invalid.'); |
|
442 | + } |
|
443 | + return $jws->payload(); |
|
444 | + } |
|
445 | 445 | |
446 | - /** |
|
447 | - * Get validated payload from an encrypted JWE. |
|
448 | - * |
|
449 | - * @param JWE $jwe JWE |
|
450 | - * @param ValidationContext $ctx Validation context |
|
451 | - * |
|
452 | - * @throws ValidationException If decryption fails |
|
453 | - * |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - private static function _validatedPayloadFromJWE(JWE $jwe, |
|
457 | - ValidationContext $ctx): string |
|
458 | - { |
|
459 | - try { |
|
460 | - $keys = $ctx->keys(); |
|
461 | - // explicitly defined key |
|
462 | - if (1 === count($keys)) { |
|
463 | - return $jwe->decryptWithJWK($keys->first()); |
|
464 | - } |
|
465 | - return $jwe->decryptWithJWKSet($keys); |
|
466 | - } catch (\RuntimeException $e) { |
|
467 | - throw new ValidationException('JWE validation failed.', 0, $e); |
|
468 | - } |
|
469 | - } |
|
446 | + /** |
|
447 | + * Get validated payload from an encrypted JWE. |
|
448 | + * |
|
449 | + * @param JWE $jwe JWE |
|
450 | + * @param ValidationContext $ctx Validation context |
|
451 | + * |
|
452 | + * @throws ValidationException If decryption fails |
|
453 | + * |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + private static function _validatedPayloadFromJWE(JWE $jwe, |
|
457 | + ValidationContext $ctx): string |
|
458 | + { |
|
459 | + try { |
|
460 | + $keys = $ctx->keys(); |
|
461 | + // explicitly defined key |
|
462 | + if (1 === count($keys)) { |
|
463 | + return $jwe->decryptWithJWK($keys->first()); |
|
464 | + } |
|
465 | + return $jwe->decryptWithJWKSet($keys); |
|
466 | + } catch (\RuntimeException $e) { |
|
467 | + throw new ValidationException('JWE validation failed.', 0, $e); |
|
468 | + } |
|
469 | + } |
|
470 | 470 | } |
@@ -69,14 +69,14 @@ |
||
69 | 69 | { |
70 | 70 | $this->_parts = explode('.', $token); |
71 | 71 | switch (count($this->_parts)) { |
72 | - case 3: |
|
73 | - $this->_type = self::TYPE_JWS; |
|
74 | - break; |
|
75 | - case 5: |
|
76 | - $this->_type = self::TYPE_JWE; |
|
77 | - break; |
|
78 | - default: |
|
79 | - throw new \UnexpectedValueException('Not a JWT token.'); |
|
72 | + case 3: |
|
73 | + $this->_type = self::TYPE_JWS; |
|
74 | + break; |
|
75 | + case 5: |
|
76 | + $this->_type = self::TYPE_JWE; |
|
77 | + break; |
|
78 | + default: |
|
79 | + throw new \UnexpectedValueException('Not a JWT token.'); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT; |
6 | 6 |
@@ -15,54 +15,54 @@ |
||
15 | 15 | */ |
16 | 16 | class JOSE extends Header |
17 | 17 | { |
18 | - /** |
|
19 | - * Constructor. |
|
20 | - * |
|
21 | - * @param Header ...$headers One or more headers to merge |
|
22 | - */ |
|
23 | - public function __construct(Header ...$headers) |
|
24 | - { |
|
25 | - $params = []; |
|
26 | - foreach ($headers as $header) { |
|
27 | - foreach ($header->parameters() as $param) { |
|
28 | - if (isset($params[$param->name()])) { |
|
29 | - throw new \UnexpectedValueException('Duplicate parameter.'); |
|
30 | - } |
|
31 | - $params[$param->name()] = $param; |
|
32 | - } |
|
33 | - } |
|
34 | - parent::__construct(...array_values($params)); |
|
35 | - } |
|
18 | + /** |
|
19 | + * Constructor. |
|
20 | + * |
|
21 | + * @param Header ...$headers One or more headers to merge |
|
22 | + */ |
|
23 | + public function __construct(Header ...$headers) |
|
24 | + { |
|
25 | + $params = []; |
|
26 | + foreach ($headers as $header) { |
|
27 | + foreach ($header->parameters() as $param) { |
|
28 | + if (isset($params[$param->name()])) { |
|
29 | + throw new \UnexpectedValueException('Duplicate parameter.'); |
|
30 | + } |
|
31 | + $params[$param->name()] = $param; |
|
32 | + } |
|
33 | + } |
|
34 | + parent::__construct(...array_values($params)); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get self merged with another Header. |
|
39 | - * |
|
40 | - * @param Header $header |
|
41 | - * |
|
42 | - * @return self |
|
43 | - */ |
|
44 | - public function withHeader(Header $header): self |
|
45 | - { |
|
46 | - return new self($this, $header); |
|
47 | - } |
|
37 | + /** |
|
38 | + * Get self merged with another Header. |
|
39 | + * |
|
40 | + * @param Header $header |
|
41 | + * |
|
42 | + * @return self |
|
43 | + */ |
|
44 | + public function withHeader(Header $header): self |
|
45 | + { |
|
46 | + return new self($this, $header); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Whether JOSE is for a JWS. |
|
51 | - * |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - public function isJWS(): bool |
|
55 | - { |
|
56 | - return $this->hasAlgorithm() && !$this->hasEncryptionAlgorithm(); |
|
57 | - } |
|
49 | + /** |
|
50 | + * Whether JOSE is for a JWS. |
|
51 | + * |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + public function isJWS(): bool |
|
55 | + { |
|
56 | + return $this->hasAlgorithm() && !$this->hasEncryptionAlgorithm(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Whether JOSE is for a JWE. |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function isJWE(): bool |
|
65 | - { |
|
66 | - return $this->hasEncryptionAlgorithm(); |
|
67 | - } |
|
59 | + /** |
|
60 | + * Whether JOSE is for a JWE. |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function isJWE(): bool |
|
65 | + { |
|
66 | + return $this->hasEncryptionAlgorithm(); |
|
67 | + } |
|
68 | 68 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Header; |
6 | 6 |
@@ -11,162 +11,162 @@ |
||
11 | 11 | */ |
12 | 12 | class Header implements \Countable, \IteratorAggregate |
13 | 13 | { |
14 | - use TypedHeader; |
|
14 | + use TypedHeader; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Parameters. |
|
18 | - * |
|
19 | - * @var JWTParameter[] |
|
20 | - */ |
|
21 | - protected $_parameters; |
|
16 | + /** |
|
17 | + * Parameters. |
|
18 | + * |
|
19 | + * @var JWTParameter[] |
|
20 | + */ |
|
21 | + protected $_parameters; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param JWTParameter ...$params Parameters |
|
27 | - */ |
|
28 | - public function __construct(JWTParameter ...$params) |
|
29 | - { |
|
30 | - $this->_parameters = []; |
|
31 | - foreach ($params as $param) { |
|
32 | - $this->_parameters[$param->name()] = $param; |
|
33 | - } |
|
34 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param JWTParameter ...$params Parameters |
|
27 | + */ |
|
28 | + public function __construct(JWTParameter ...$params) |
|
29 | + { |
|
30 | + $this->_parameters = []; |
|
31 | + foreach ($params as $param) { |
|
32 | + $this->_parameters[$param->name()] = $param; |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initialize from an array representing a JSON object. |
|
38 | - * |
|
39 | - * @param array $members |
|
40 | - * |
|
41 | - * @return self |
|
42 | - */ |
|
43 | - public static function fromArray(array $members): self |
|
44 | - { |
|
45 | - $params = []; |
|
46 | - foreach ($members as $name => $value) { |
|
47 | - $params[] = JWTParameter::fromNameAndValue($name, $value); |
|
48 | - } |
|
49 | - return new self(...$params); |
|
50 | - } |
|
36 | + /** |
|
37 | + * Initialize from an array representing a JSON object. |
|
38 | + * |
|
39 | + * @param array $members |
|
40 | + * |
|
41 | + * @return self |
|
42 | + */ |
|
43 | + public static function fromArray(array $members): self |
|
44 | + { |
|
45 | + $params = []; |
|
46 | + foreach ($members as $name => $value) { |
|
47 | + $params[] = JWTParameter::fromNameAndValue($name, $value); |
|
48 | + } |
|
49 | + return new self(...$params); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Initialize from a JSON. |
|
54 | - * |
|
55 | - * @param string $json |
|
56 | - * |
|
57 | - * @throws \UnexpectedValueException |
|
58 | - * |
|
59 | - * @return self |
|
60 | - */ |
|
61 | - public static function fromJSON(string $json): self |
|
62 | - { |
|
63 | - $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
64 | - if (!is_array($members)) { |
|
65 | - throw new \UnexpectedValueException('Invalid JSON.'); |
|
66 | - } |
|
67 | - return self::fromArray($members); |
|
68 | - } |
|
52 | + /** |
|
53 | + * Initialize from a JSON. |
|
54 | + * |
|
55 | + * @param string $json |
|
56 | + * |
|
57 | + * @throws \UnexpectedValueException |
|
58 | + * |
|
59 | + * @return self |
|
60 | + */ |
|
61 | + public static function fromJSON(string $json): self |
|
62 | + { |
|
63 | + $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
64 | + if (!is_array($members)) { |
|
65 | + throw new \UnexpectedValueException('Invalid JSON.'); |
|
66 | + } |
|
67 | + return self::fromArray($members); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get self with parameters added. |
|
72 | - * |
|
73 | - * @param JWTParameter ...$param |
|
74 | - * |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - public function withParameters(JWTParameter ...$params): self |
|
78 | - { |
|
79 | - $obj = clone $this; |
|
80 | - foreach ($params as $param) { |
|
81 | - $obj->_parameters[$param->name()] = $param; |
|
82 | - } |
|
83 | - return $obj; |
|
84 | - } |
|
70 | + /** |
|
71 | + * Get self with parameters added. |
|
72 | + * |
|
73 | + * @param JWTParameter ...$param |
|
74 | + * |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + public function withParameters(JWTParameter ...$params): self |
|
78 | + { |
|
79 | + $obj = clone $this; |
|
80 | + foreach ($params as $param) { |
|
81 | + $obj->_parameters[$param->name()] = $param; |
|
82 | + } |
|
83 | + return $obj; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get all parameters. |
|
88 | - * |
|
89 | - * @return JWTParameter[] |
|
90 | - */ |
|
91 | - public function parameters(): array |
|
92 | - { |
|
93 | - return $this->_parameters; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Get all parameters. |
|
88 | + * |
|
89 | + * @return JWTParameter[] |
|
90 | + */ |
|
91 | + public function parameters(): array |
|
92 | + { |
|
93 | + return $this->_parameters; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Whether parameters are present. |
|
98 | - * |
|
99 | - * Returns false if any of the given parameters is not set. |
|
100 | - * |
|
101 | - * @param string ...$names Parameter names |
|
102 | - * |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public function has(string ...$names): bool |
|
106 | - { |
|
107 | - foreach ($names as $name) { |
|
108 | - if (!isset($this->_parameters[$name])) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - } |
|
112 | - return true; |
|
113 | - } |
|
96 | + /** |
|
97 | + * Whether parameters are present. |
|
98 | + * |
|
99 | + * Returns false if any of the given parameters is not set. |
|
100 | + * |
|
101 | + * @param string ...$names Parameter names |
|
102 | + * |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public function has(string ...$names): bool |
|
106 | + { |
|
107 | + foreach ($names as $name) { |
|
108 | + if (!isset($this->_parameters[$name])) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + } |
|
112 | + return true; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get a parameter. |
|
117 | - * |
|
118 | - * @param string $name Parameter name |
|
119 | - * |
|
120 | - * @throws \LogicException |
|
121 | - * |
|
122 | - * @return JWTParameter |
|
123 | - */ |
|
124 | - public function get(string $name): JWTParameter |
|
125 | - { |
|
126 | - if (!$this->has($name)) { |
|
127 | - throw new \LogicException("Parameter {$name} doesn't exists."); |
|
128 | - } |
|
129 | - return $this->_parameters[$name]; |
|
130 | - } |
|
115 | + /** |
|
116 | + * Get a parameter. |
|
117 | + * |
|
118 | + * @param string $name Parameter name |
|
119 | + * |
|
120 | + * @throws \LogicException |
|
121 | + * |
|
122 | + * @return JWTParameter |
|
123 | + */ |
|
124 | + public function get(string $name): JWTParameter |
|
125 | + { |
|
126 | + if (!$this->has($name)) { |
|
127 | + throw new \LogicException("Parameter {$name} doesn't exists."); |
|
128 | + } |
|
129 | + return $this->_parameters[$name]; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Convert to a JSON. |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function toJSON(): string |
|
138 | - { |
|
139 | - if (empty($this->_parameters)) { |
|
140 | - return ''; |
|
141 | - } |
|
142 | - $data = []; |
|
143 | - foreach ($this->_parameters as $param) { |
|
144 | - $data[$param->name()] = $param->value(); |
|
145 | - } |
|
146 | - return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
147 | - } |
|
132 | + /** |
|
133 | + * Convert to a JSON. |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function toJSON(): string |
|
138 | + { |
|
139 | + if (empty($this->_parameters)) { |
|
140 | + return ''; |
|
141 | + } |
|
142 | + $data = []; |
|
143 | + foreach ($this->_parameters as $param) { |
|
144 | + $data[$param->name()] = $param->value(); |
|
145 | + } |
|
146 | + return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Get the number of parameters. |
|
151 | - * |
|
152 | - * @see \Countable::count() |
|
153 | - * |
|
154 | - * @return int |
|
155 | - */ |
|
156 | - public function count(): int |
|
157 | - { |
|
158 | - return count($this->_parameters); |
|
159 | - } |
|
149 | + /** |
|
150 | + * Get the number of parameters. |
|
151 | + * |
|
152 | + * @see \Countable::count() |
|
153 | + * |
|
154 | + * @return int |
|
155 | + */ |
|
156 | + public function count(): int |
|
157 | + { |
|
158 | + return count($this->_parameters); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Get iterator for the parameters. |
|
163 | - * |
|
164 | - * @see \IteratorAggregate::getIterator() |
|
165 | - * |
|
166 | - * @return \ArrayIterator |
|
167 | - */ |
|
168 | - public function getIterator(): \ArrayIterator |
|
169 | - { |
|
170 | - return new \ArrayIterator($this->_parameters); |
|
171 | - } |
|
161 | + /** |
|
162 | + * Get iterator for the parameters. |
|
163 | + * |
|
164 | + * @see \IteratorAggregate::getIterator() |
|
165 | + * |
|
166 | + * @return \ArrayIterator |
|
167 | + */ |
|
168 | + public function getIterator(): \ArrayIterator |
|
169 | + { |
|
170 | + return new \ArrayIterator($this->_parameters); |
|
171 | + } |
|
172 | 172 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Header; |
6 | 6 |
@@ -11,10 +11,10 @@ |
||
11 | 11 | */ |
12 | 12 | interface HeaderParameters |
13 | 13 | { |
14 | - /** |
|
15 | - * Get an array of JOSE header parameters representing this object. |
|
16 | - * |
|
17 | - * @return JWTParameter[] |
|
18 | - */ |
|
19 | - public function headerParameters(): array; |
|
14 | + /** |
|
15 | + * Get an array of JOSE header parameters representing this object. |
|
16 | + * |
|
17 | + * @return JWTParameter[] |
|
18 | + */ |
|
19 | + public function headerParameters(): array; |
|
20 | 20 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Header; |
6 | 6 |
@@ -13,476 +13,476 @@ |
||
13 | 13 | */ |
14 | 14 | trait TypedHeader |
15 | 15 | { |
16 | - /** |
|
17 | - * Whether parameters are present. |
|
18 | - * |
|
19 | - * @param string ...$names Parameter names |
|
20 | - * |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - abstract public function has(string ...$names): bool; |
|
24 | - |
|
25 | - /** |
|
26 | - * Get a parameter. |
|
27 | - * |
|
28 | - * @param string $name Parameter name |
|
29 | - * |
|
30 | - * @throws \LogicException If the parameter is not present |
|
31 | - * |
|
32 | - * @return JWTParameter |
|
33 | - */ |
|
34 | - abstract public function get(string $name): JWTParameter; |
|
35 | - |
|
36 | - /** |
|
37 | - * Check whether the algorithm parameter is present. |
|
38 | - * |
|
39 | - * @return bool |
|
40 | - */ |
|
41 | - public function hasAlgorithm(): bool |
|
42 | - { |
|
43 | - return $this->has(Parameter\JWTParameter::P_ALG); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Get the algorithm parameter. |
|
48 | - * |
|
49 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
50 | - * @throws \LogicException If the parameter is not present |
|
51 | - * |
|
52 | - * @return \Sop\JWX\JWT\Parameter\AlgorithmParameter |
|
53 | - */ |
|
54 | - public function algorithm(): Parameter\AlgorithmParameter |
|
55 | - { |
|
56 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ALG), |
|
57 | - Parameter\AlgorithmParameter::class); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Check whether the authentication tag parameter is present. |
|
62 | - * |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function hasAuthenticationTag(): bool |
|
66 | - { |
|
67 | - return $this->has(Parameter\JWTParameter::P_TAG); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Get the authentication tag parameter. |
|
72 | - * |
|
73 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
74 | - * @throws \LogicException If the parameter is not present |
|
75 | - * |
|
76 | - * @return \Sop\JWX\JWT\Parameter\AuthenticationTagParameter |
|
77 | - */ |
|
78 | - public function authenticationTag(): Parameter\AuthenticationTagParameter |
|
79 | - { |
|
80 | - return self::_checkType($this->get(Parameter\JWTParameter::P_TAG), |
|
81 | - Parameter\AuthenticationTagParameter::class); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check whether the 'base64url-encode payload' parameter is present. |
|
86 | - * |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function hasB64Payload(): bool |
|
90 | - { |
|
91 | - return $this->has(Parameter\JWTParameter::P_B64); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Get the 'base64url-encode payload' parameter. |
|
96 | - * |
|
97 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
98 | - * @throws \LogicException If the parameter is not present |
|
99 | - * |
|
100 | - * @return \Sop\JWX\JWT\Parameter\B64PayloadParameter |
|
101 | - */ |
|
102 | - public function B64Payload(): Parameter\B64PayloadParameter |
|
103 | - { |
|
104 | - return self::_checkType($this->get(Parameter\JWTParameter::P_B64), |
|
105 | - Parameter\B64PayloadParameter::class); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Check whether the compression algorithm parameter is present. |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function hasCompressionAlgorithm(): bool |
|
114 | - { |
|
115 | - return $this->has(Parameter\JWTParameter::P_ZIP); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get the compression algorithm parameter. |
|
120 | - * |
|
121 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
122 | - * @throws \LogicException If the parameter is not present |
|
123 | - * |
|
124 | - * @return \Sop\JWX\JWT\Parameter\CompressionAlgorithmParameter |
|
125 | - */ |
|
126 | - public function compressionAlgorithm(): Parameter\CompressionAlgorithmParameter |
|
127 | - { |
|
128 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ZIP), |
|
129 | - Parameter\CompressionAlgorithmParameter::class); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Check whether the content type parameter is present. |
|
134 | - * |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - public function hasContentType(): bool |
|
138 | - { |
|
139 | - return $this->has(Parameter\JWTParameter::P_CTY); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Get the content type parameter. |
|
144 | - * |
|
145 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
146 | - * @throws \LogicException If the parameter is not present |
|
147 | - * |
|
148 | - * @return \Sop\JWX\JWT\Parameter\ContentTypeParameter |
|
149 | - */ |
|
150 | - public function contentType(): Parameter\ContentTypeParameter |
|
151 | - { |
|
152 | - return self::_checkType($this->get(Parameter\JWTParameter::P_CTY), |
|
153 | - Parameter\ContentTypeParameter::class); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Check whether the critical parameter is present. |
|
158 | - * |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function hasCritical(): bool |
|
162 | - { |
|
163 | - return $this->has(Parameter\JWTParameter::P_CRIT); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Get the critical parameter. |
|
168 | - * |
|
169 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
170 | - * @throws \LogicException If the parameter is not present |
|
171 | - * |
|
172 | - * @return \Sop\JWX\JWT\Parameter\CriticalParameter |
|
173 | - */ |
|
174 | - public function critical(): Parameter\CriticalParameter |
|
175 | - { |
|
176 | - return self::_checkType($this->get(Parameter\JWTParameter::P_CRIT), |
|
177 | - Parameter\CriticalParameter::class); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Check whether the encryption algorithm parameter is present. |
|
182 | - * |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function hasEncryptionAlgorithm(): bool |
|
186 | - { |
|
187 | - return $this->has(Parameter\JWTParameter::P_ENC); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Get the encryption algorithm parameter. |
|
192 | - * |
|
193 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
194 | - * @throws \LogicException If the parameter is not present |
|
195 | - * |
|
196 | - * @return \Sop\JWX\JWT\Parameter\EncryptionAlgorithmParameter |
|
197 | - */ |
|
198 | - public function encryptionAlgorithm(): Parameter\EncryptionAlgorithmParameter |
|
199 | - { |
|
200 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ENC), |
|
201 | - Parameter\EncryptionAlgorithmParameter::class); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Check whether the initialization vector parameter is present. |
|
206 | - * |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function hasInitializationVector(): bool |
|
210 | - { |
|
211 | - return $this->has(Parameter\JWTParameter::P_IV); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Get the initialization vector parameter. |
|
216 | - * |
|
217 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
218 | - * @throws \LogicException If the parameter is not present |
|
219 | - * |
|
220 | - * @return \Sop\JWX\JWT\Parameter\InitializationVectorParameter |
|
221 | - */ |
|
222 | - public function initializationVector(): Parameter\InitializationVectorParameter |
|
223 | - { |
|
224 | - return self::_checkType($this->get(Parameter\JWTParameter::P_IV), |
|
225 | - Parameter\InitializationVectorParameter::class); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Check whether the JSON web key parameter is present. |
|
230 | - * |
|
231 | - * @return bool |
|
232 | - */ |
|
233 | - public function hasJSONWebKey(): bool |
|
234 | - { |
|
235 | - return $this->has(Parameter\JWTParameter::P_JWK); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the JSON web key parameter. |
|
240 | - * |
|
241 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
242 | - * @throws \LogicException If the parameter is not present |
|
243 | - * |
|
244 | - * @return \Sop\JWX\JWT\Parameter\JSONWebKeyParameter |
|
245 | - */ |
|
246 | - public function JSONWebKey(): Parameter\JSONWebKeyParameter |
|
247 | - { |
|
248 | - return self::_checkType($this->get(Parameter\JWTParameter::P_JWK), |
|
249 | - Parameter\JSONWebKeyParameter::class); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Check whether the JWK set URL parameter is present. |
|
254 | - * |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function hasJWKSetURL(): bool |
|
258 | - { |
|
259 | - return $this->has(Parameter\JWTParameter::P_JKU); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get the JWK set URL parameter. |
|
264 | - * |
|
265 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
266 | - * @throws \LogicException If the parameter is not present |
|
267 | - * |
|
268 | - * @return \Sop\JWX\JWT\Parameter\JWKSetURLParameter |
|
269 | - */ |
|
270 | - public function JWKSetURL(): Parameter\JWKSetURLParameter |
|
271 | - { |
|
272 | - return self::_checkType($this->get(Parameter\JWTParameter::P_JKU), |
|
273 | - Parameter\JWKSetURLParameter::class); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Check whether the key ID parameter is present. |
|
278 | - * |
|
279 | - * @return bool |
|
280 | - */ |
|
281 | - public function hasKeyID(): bool |
|
282 | - { |
|
283 | - return $this->has(Parameter\JWTParameter::P_KID); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Get the key ID parameter. |
|
288 | - * |
|
289 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
290 | - * @throws \LogicException If the parameter is not present |
|
291 | - * |
|
292 | - * @return \Sop\JWX\JWT\Parameter\KeyIDParameter |
|
293 | - */ |
|
294 | - public function keyID(): Parameter\KeyIDParameter |
|
295 | - { |
|
296 | - return self::_checkType($this->get(Parameter\JWTParameter::P_KID), |
|
297 | - Parameter\KeyIDParameter::class); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Check whether the PBES2 count parameter is present. |
|
302 | - * |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - public function hasPBES2Count(): bool |
|
306 | - { |
|
307 | - return $this->has(Parameter\JWTParameter::P_P2C); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get the PBES2 count parameter. |
|
312 | - * |
|
313 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
314 | - * @throws \LogicException If the parameter is not present |
|
315 | - * |
|
316 | - * @return \Sop\JWX\JWT\Parameter\PBES2CountParameter |
|
317 | - */ |
|
318 | - public function PBES2Count(): Parameter\PBES2CountParameter |
|
319 | - { |
|
320 | - return self::_checkType($this->get(Parameter\JWTParameter::P_P2C), |
|
321 | - Parameter\PBES2CountParameter::class); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Check whether the PBES2 salt input parameter is present. |
|
326 | - * |
|
327 | - * @return bool |
|
328 | - */ |
|
329 | - public function hasPBES2SaltInput(): bool |
|
330 | - { |
|
331 | - return $this->has(Parameter\JWTParameter::P_P2S); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Get the PBES2 salt input parameter. |
|
336 | - * |
|
337 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
338 | - * @throws \LogicException If the parameter is not present |
|
339 | - * |
|
340 | - * @return \Sop\JWX\JWT\Parameter\PBES2SaltInputParameter |
|
341 | - */ |
|
342 | - public function PBES2SaltInput(): Parameter\PBES2SaltInputParameter |
|
343 | - { |
|
344 | - return self::_checkType($this->get(Parameter\JWTParameter::P_P2S), |
|
345 | - Parameter\PBES2SaltInputParameter::class); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Check whether the type parameter is present. |
|
350 | - * |
|
351 | - * @return bool |
|
352 | - */ |
|
353 | - public function hasType(): bool |
|
354 | - { |
|
355 | - return $this->has(Parameter\JWTParameter::P_TYP); |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Get the type parameter. |
|
360 | - * |
|
361 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
362 | - * @throws \LogicException If the parameter is not present |
|
363 | - * |
|
364 | - * @return \Sop\JWX\JWT\Parameter\TypeParameter |
|
365 | - */ |
|
366 | - public function type(): Parameter\TypeParameter |
|
367 | - { |
|
368 | - return self::_checkType($this->get(Parameter\JWTParameter::P_TYP), |
|
369 | - Parameter\TypeParameter::class); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Check whether the X.509 certificate chain parameter is present. |
|
374 | - * |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - public function hasX509CertificateChain(): bool |
|
378 | - { |
|
379 | - return $this->has(Parameter\JWTParameter::P_X5C); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Get the X.509 certificate chain parameter. |
|
384 | - * |
|
385 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
386 | - * @throws \LogicException If the parameter is not present |
|
387 | - * |
|
388 | - * @return \Sop\JWX\JWT\Parameter\X509CertificateChainParameter |
|
389 | - */ |
|
390 | - public function X509CertificateChain(): Parameter\X509CertificateChainParameter |
|
391 | - { |
|
392 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5C), |
|
393 | - Parameter\X509CertificateChainParameter::class); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
398 | - * present. |
|
399 | - * |
|
400 | - * @return bool |
|
401 | - */ |
|
402 | - public function hasX509CertificateSHA1Thumbprint(): bool |
|
403 | - { |
|
404 | - return $this->has(Parameter\JWTParameter::P_X5T); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
409 | - * |
|
410 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
411 | - * @throws \LogicException If the parameter is not present |
|
412 | - * |
|
413 | - * @return \Sop\JWX\JWT\Parameter\X509CertificateSHA1ThumbprintParameter |
|
414 | - */ |
|
415 | - public function X509CertificateSHA1Thumbprint(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
416 | - { |
|
417 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5T), |
|
418 | - Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
423 | - * present. |
|
424 | - * |
|
425 | - * @return bool |
|
426 | - */ |
|
427 | - public function hasX509CertificateSHA256Thumbprint(): bool |
|
428 | - { |
|
429 | - return $this->has(Parameter\JWTParameter::P_X5TS256); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
434 | - * |
|
435 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
436 | - * @throws \LogicException If the parameter is not present |
|
437 | - * |
|
438 | - * @return \Sop\JWX\JWT\Parameter\X509CertificateSHA256ThumbprintParameter |
|
439 | - */ |
|
440 | - public function X509CertificateSHA256Thumbprint(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
441 | - { |
|
442 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5TS256), |
|
443 | - Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Check whether the X.509 URL parameter is present. |
|
448 | - * |
|
449 | - * @return bool |
|
450 | - */ |
|
451 | - public function hasX509URL(): bool |
|
452 | - { |
|
453 | - return $this->has(Parameter\JWTParameter::P_X5U); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Get the X.509 URL parameter. |
|
458 | - * |
|
459 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
460 | - * @throws \LogicException If the parameter is not present |
|
461 | - * |
|
462 | - * @return \Sop\JWX\JWT\Parameter\X509URLParameter |
|
463 | - */ |
|
464 | - public function X509URL(): Parameter\X509URLParameter |
|
465 | - { |
|
466 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5U), |
|
467 | - Parameter\X509URLParameter::class); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Check that the parameter is an instance of the given class. |
|
472 | - * |
|
473 | - * @param \Sop\JWX\JWT\Parameter\JWTParameter $param Parameter |
|
474 | - * @param string $cls Class name |
|
475 | - * |
|
476 | - * @throws \UnexpectedValueException |
|
477 | - * |
|
478 | - * @return \Sop\JWX\JWT\Parameter\JWTParameter |
|
479 | - */ |
|
480 | - private static function _checkType(Parameter\JWTParameter $param, string $cls): Parameter\JWTParameter |
|
481 | - { |
|
482 | - if (!$param instanceof $cls) { |
|
483 | - throw new \UnexpectedValueException( |
|
484 | - "{$cls} expected, got " . get_class($param)); |
|
485 | - } |
|
486 | - return $param; |
|
487 | - } |
|
16 | + /** |
|
17 | + * Whether parameters are present. |
|
18 | + * |
|
19 | + * @param string ...$names Parameter names |
|
20 | + * |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + abstract public function has(string ...$names): bool; |
|
24 | + |
|
25 | + /** |
|
26 | + * Get a parameter. |
|
27 | + * |
|
28 | + * @param string $name Parameter name |
|
29 | + * |
|
30 | + * @throws \LogicException If the parameter is not present |
|
31 | + * |
|
32 | + * @return JWTParameter |
|
33 | + */ |
|
34 | + abstract public function get(string $name): JWTParameter; |
|
35 | + |
|
36 | + /** |
|
37 | + * Check whether the algorithm parameter is present. |
|
38 | + * |
|
39 | + * @return bool |
|
40 | + */ |
|
41 | + public function hasAlgorithm(): bool |
|
42 | + { |
|
43 | + return $this->has(Parameter\JWTParameter::P_ALG); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Get the algorithm parameter. |
|
48 | + * |
|
49 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
50 | + * @throws \LogicException If the parameter is not present |
|
51 | + * |
|
52 | + * @return \Sop\JWX\JWT\Parameter\AlgorithmParameter |
|
53 | + */ |
|
54 | + public function algorithm(): Parameter\AlgorithmParameter |
|
55 | + { |
|
56 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ALG), |
|
57 | + Parameter\AlgorithmParameter::class); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Check whether the authentication tag parameter is present. |
|
62 | + * |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function hasAuthenticationTag(): bool |
|
66 | + { |
|
67 | + return $this->has(Parameter\JWTParameter::P_TAG); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Get the authentication tag parameter. |
|
72 | + * |
|
73 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
74 | + * @throws \LogicException If the parameter is not present |
|
75 | + * |
|
76 | + * @return \Sop\JWX\JWT\Parameter\AuthenticationTagParameter |
|
77 | + */ |
|
78 | + public function authenticationTag(): Parameter\AuthenticationTagParameter |
|
79 | + { |
|
80 | + return self::_checkType($this->get(Parameter\JWTParameter::P_TAG), |
|
81 | + Parameter\AuthenticationTagParameter::class); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check whether the 'base64url-encode payload' parameter is present. |
|
86 | + * |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function hasB64Payload(): bool |
|
90 | + { |
|
91 | + return $this->has(Parameter\JWTParameter::P_B64); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Get the 'base64url-encode payload' parameter. |
|
96 | + * |
|
97 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
98 | + * @throws \LogicException If the parameter is not present |
|
99 | + * |
|
100 | + * @return \Sop\JWX\JWT\Parameter\B64PayloadParameter |
|
101 | + */ |
|
102 | + public function B64Payload(): Parameter\B64PayloadParameter |
|
103 | + { |
|
104 | + return self::_checkType($this->get(Parameter\JWTParameter::P_B64), |
|
105 | + Parameter\B64PayloadParameter::class); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Check whether the compression algorithm parameter is present. |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function hasCompressionAlgorithm(): bool |
|
114 | + { |
|
115 | + return $this->has(Parameter\JWTParameter::P_ZIP); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get the compression algorithm parameter. |
|
120 | + * |
|
121 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
122 | + * @throws \LogicException If the parameter is not present |
|
123 | + * |
|
124 | + * @return \Sop\JWX\JWT\Parameter\CompressionAlgorithmParameter |
|
125 | + */ |
|
126 | + public function compressionAlgorithm(): Parameter\CompressionAlgorithmParameter |
|
127 | + { |
|
128 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ZIP), |
|
129 | + Parameter\CompressionAlgorithmParameter::class); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Check whether the content type parameter is present. |
|
134 | + * |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + public function hasContentType(): bool |
|
138 | + { |
|
139 | + return $this->has(Parameter\JWTParameter::P_CTY); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Get the content type parameter. |
|
144 | + * |
|
145 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
146 | + * @throws \LogicException If the parameter is not present |
|
147 | + * |
|
148 | + * @return \Sop\JWX\JWT\Parameter\ContentTypeParameter |
|
149 | + */ |
|
150 | + public function contentType(): Parameter\ContentTypeParameter |
|
151 | + { |
|
152 | + return self::_checkType($this->get(Parameter\JWTParameter::P_CTY), |
|
153 | + Parameter\ContentTypeParameter::class); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Check whether the critical parameter is present. |
|
158 | + * |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function hasCritical(): bool |
|
162 | + { |
|
163 | + return $this->has(Parameter\JWTParameter::P_CRIT); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Get the critical parameter. |
|
168 | + * |
|
169 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
170 | + * @throws \LogicException If the parameter is not present |
|
171 | + * |
|
172 | + * @return \Sop\JWX\JWT\Parameter\CriticalParameter |
|
173 | + */ |
|
174 | + public function critical(): Parameter\CriticalParameter |
|
175 | + { |
|
176 | + return self::_checkType($this->get(Parameter\JWTParameter::P_CRIT), |
|
177 | + Parameter\CriticalParameter::class); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Check whether the encryption algorithm parameter is present. |
|
182 | + * |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function hasEncryptionAlgorithm(): bool |
|
186 | + { |
|
187 | + return $this->has(Parameter\JWTParameter::P_ENC); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Get the encryption algorithm parameter. |
|
192 | + * |
|
193 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
194 | + * @throws \LogicException If the parameter is not present |
|
195 | + * |
|
196 | + * @return \Sop\JWX\JWT\Parameter\EncryptionAlgorithmParameter |
|
197 | + */ |
|
198 | + public function encryptionAlgorithm(): Parameter\EncryptionAlgorithmParameter |
|
199 | + { |
|
200 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ENC), |
|
201 | + Parameter\EncryptionAlgorithmParameter::class); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Check whether the initialization vector parameter is present. |
|
206 | + * |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function hasInitializationVector(): bool |
|
210 | + { |
|
211 | + return $this->has(Parameter\JWTParameter::P_IV); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Get the initialization vector parameter. |
|
216 | + * |
|
217 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
218 | + * @throws \LogicException If the parameter is not present |
|
219 | + * |
|
220 | + * @return \Sop\JWX\JWT\Parameter\InitializationVectorParameter |
|
221 | + */ |
|
222 | + public function initializationVector(): Parameter\InitializationVectorParameter |
|
223 | + { |
|
224 | + return self::_checkType($this->get(Parameter\JWTParameter::P_IV), |
|
225 | + Parameter\InitializationVectorParameter::class); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Check whether the JSON web key parameter is present. |
|
230 | + * |
|
231 | + * @return bool |
|
232 | + */ |
|
233 | + public function hasJSONWebKey(): bool |
|
234 | + { |
|
235 | + return $this->has(Parameter\JWTParameter::P_JWK); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the JSON web key parameter. |
|
240 | + * |
|
241 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
242 | + * @throws \LogicException If the parameter is not present |
|
243 | + * |
|
244 | + * @return \Sop\JWX\JWT\Parameter\JSONWebKeyParameter |
|
245 | + */ |
|
246 | + public function JSONWebKey(): Parameter\JSONWebKeyParameter |
|
247 | + { |
|
248 | + return self::_checkType($this->get(Parameter\JWTParameter::P_JWK), |
|
249 | + Parameter\JSONWebKeyParameter::class); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Check whether the JWK set URL parameter is present. |
|
254 | + * |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function hasJWKSetURL(): bool |
|
258 | + { |
|
259 | + return $this->has(Parameter\JWTParameter::P_JKU); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get the JWK set URL parameter. |
|
264 | + * |
|
265 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
266 | + * @throws \LogicException If the parameter is not present |
|
267 | + * |
|
268 | + * @return \Sop\JWX\JWT\Parameter\JWKSetURLParameter |
|
269 | + */ |
|
270 | + public function JWKSetURL(): Parameter\JWKSetURLParameter |
|
271 | + { |
|
272 | + return self::_checkType($this->get(Parameter\JWTParameter::P_JKU), |
|
273 | + Parameter\JWKSetURLParameter::class); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Check whether the key ID parameter is present. |
|
278 | + * |
|
279 | + * @return bool |
|
280 | + */ |
|
281 | + public function hasKeyID(): bool |
|
282 | + { |
|
283 | + return $this->has(Parameter\JWTParameter::P_KID); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Get the key ID parameter. |
|
288 | + * |
|
289 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
290 | + * @throws \LogicException If the parameter is not present |
|
291 | + * |
|
292 | + * @return \Sop\JWX\JWT\Parameter\KeyIDParameter |
|
293 | + */ |
|
294 | + public function keyID(): Parameter\KeyIDParameter |
|
295 | + { |
|
296 | + return self::_checkType($this->get(Parameter\JWTParameter::P_KID), |
|
297 | + Parameter\KeyIDParameter::class); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Check whether the PBES2 count parameter is present. |
|
302 | + * |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + public function hasPBES2Count(): bool |
|
306 | + { |
|
307 | + return $this->has(Parameter\JWTParameter::P_P2C); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get the PBES2 count parameter. |
|
312 | + * |
|
313 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
314 | + * @throws \LogicException If the parameter is not present |
|
315 | + * |
|
316 | + * @return \Sop\JWX\JWT\Parameter\PBES2CountParameter |
|
317 | + */ |
|
318 | + public function PBES2Count(): Parameter\PBES2CountParameter |
|
319 | + { |
|
320 | + return self::_checkType($this->get(Parameter\JWTParameter::P_P2C), |
|
321 | + Parameter\PBES2CountParameter::class); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Check whether the PBES2 salt input parameter is present. |
|
326 | + * |
|
327 | + * @return bool |
|
328 | + */ |
|
329 | + public function hasPBES2SaltInput(): bool |
|
330 | + { |
|
331 | + return $this->has(Parameter\JWTParameter::P_P2S); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Get the PBES2 salt input parameter. |
|
336 | + * |
|
337 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
338 | + * @throws \LogicException If the parameter is not present |
|
339 | + * |
|
340 | + * @return \Sop\JWX\JWT\Parameter\PBES2SaltInputParameter |
|
341 | + */ |
|
342 | + public function PBES2SaltInput(): Parameter\PBES2SaltInputParameter |
|
343 | + { |
|
344 | + return self::_checkType($this->get(Parameter\JWTParameter::P_P2S), |
|
345 | + Parameter\PBES2SaltInputParameter::class); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Check whether the type parameter is present. |
|
350 | + * |
|
351 | + * @return bool |
|
352 | + */ |
|
353 | + public function hasType(): bool |
|
354 | + { |
|
355 | + return $this->has(Parameter\JWTParameter::P_TYP); |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Get the type parameter. |
|
360 | + * |
|
361 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
362 | + * @throws \LogicException If the parameter is not present |
|
363 | + * |
|
364 | + * @return \Sop\JWX\JWT\Parameter\TypeParameter |
|
365 | + */ |
|
366 | + public function type(): Parameter\TypeParameter |
|
367 | + { |
|
368 | + return self::_checkType($this->get(Parameter\JWTParameter::P_TYP), |
|
369 | + Parameter\TypeParameter::class); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Check whether the X.509 certificate chain parameter is present. |
|
374 | + * |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + public function hasX509CertificateChain(): bool |
|
378 | + { |
|
379 | + return $this->has(Parameter\JWTParameter::P_X5C); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Get the X.509 certificate chain parameter. |
|
384 | + * |
|
385 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
386 | + * @throws \LogicException If the parameter is not present |
|
387 | + * |
|
388 | + * @return \Sop\JWX\JWT\Parameter\X509CertificateChainParameter |
|
389 | + */ |
|
390 | + public function X509CertificateChain(): Parameter\X509CertificateChainParameter |
|
391 | + { |
|
392 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5C), |
|
393 | + Parameter\X509CertificateChainParameter::class); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
398 | + * present. |
|
399 | + * |
|
400 | + * @return bool |
|
401 | + */ |
|
402 | + public function hasX509CertificateSHA1Thumbprint(): bool |
|
403 | + { |
|
404 | + return $this->has(Parameter\JWTParameter::P_X5T); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
409 | + * |
|
410 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
411 | + * @throws \LogicException If the parameter is not present |
|
412 | + * |
|
413 | + * @return \Sop\JWX\JWT\Parameter\X509CertificateSHA1ThumbprintParameter |
|
414 | + */ |
|
415 | + public function X509CertificateSHA1Thumbprint(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
416 | + { |
|
417 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5T), |
|
418 | + Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
423 | + * present. |
|
424 | + * |
|
425 | + * @return bool |
|
426 | + */ |
|
427 | + public function hasX509CertificateSHA256Thumbprint(): bool |
|
428 | + { |
|
429 | + return $this->has(Parameter\JWTParameter::P_X5TS256); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
434 | + * |
|
435 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
436 | + * @throws \LogicException If the parameter is not present |
|
437 | + * |
|
438 | + * @return \Sop\JWX\JWT\Parameter\X509CertificateSHA256ThumbprintParameter |
|
439 | + */ |
|
440 | + public function X509CertificateSHA256Thumbprint(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
441 | + { |
|
442 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5TS256), |
|
443 | + Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Check whether the X.509 URL parameter is present. |
|
448 | + * |
|
449 | + * @return bool |
|
450 | + */ |
|
451 | + public function hasX509URL(): bool |
|
452 | + { |
|
453 | + return $this->has(Parameter\JWTParameter::P_X5U); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Get the X.509 URL parameter. |
|
458 | + * |
|
459 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
460 | + * @throws \LogicException If the parameter is not present |
|
461 | + * |
|
462 | + * @return \Sop\JWX\JWT\Parameter\X509URLParameter |
|
463 | + */ |
|
464 | + public function X509URL(): Parameter\X509URLParameter |
|
465 | + { |
|
466 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5U), |
|
467 | + Parameter\X509URLParameter::class); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Check that the parameter is an instance of the given class. |
|
472 | + * |
|
473 | + * @param \Sop\JWX\JWT\Parameter\JWTParameter $param Parameter |
|
474 | + * @param string $cls Class name |
|
475 | + * |
|
476 | + * @throws \UnexpectedValueException |
|
477 | + * |
|
478 | + * @return \Sop\JWX\JWT\Parameter\JWTParameter |
|
479 | + */ |
|
480 | + private static function _checkType(Parameter\JWTParameter $param, string $cls): Parameter\JWTParameter |
|
481 | + { |
|
482 | + if (!$param instanceof $cls) { |
|
483 | + throw new \UnexpectedValueException( |
|
484 | + "{$cls} expected, got " . get_class($param)); |
|
485 | + } |
|
486 | + return $param; |
|
487 | + } |
|
488 | 488 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Header; |
6 | 6 |
@@ -26,326 +26,326 @@ |
||
26 | 26 | */ |
27 | 27 | class ValidationContext |
28 | 28 | { |
29 | - /** |
|
30 | - * Reference time. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - protected $_refTime; |
|
29 | + /** |
|
30 | + * Reference time. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + protected $_refTime; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Leeway in seconds for the reference time constraints. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - protected $_leeway; |
|
36 | + /** |
|
37 | + * Leeway in seconds for the reference time constraints. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + protected $_leeway; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Validation constraints. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $_constraints; |
|
43 | + /** |
|
44 | + * Validation constraints. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $_constraints; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Explicitly defined validators for named claims. |
|
52 | - * |
|
53 | - * @var Validator[] |
|
54 | - */ |
|
55 | - protected $_validators; |
|
50 | + /** |
|
51 | + * Explicitly defined validators for named claims. |
|
52 | + * |
|
53 | + * @var Validator[] |
|
54 | + */ |
|
55 | + protected $_validators; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Set of JSON Web Keys usable for the validation. |
|
59 | - * |
|
60 | - * @var JWKSet |
|
61 | - */ |
|
62 | - protected $_keys; |
|
57 | + /** |
|
58 | + * Set of JSON Web Keys usable for the validation. |
|
59 | + * |
|
60 | + * @var JWKSet |
|
61 | + */ |
|
62 | + protected $_keys; |
|
63 | 63 | |
64 | - /** |
|
65 | - * Whether to allow unsecured JWT's, that is, claims without integrity |
|
66 | - * protection nor encryption. |
|
67 | - * |
|
68 | - * @var bool |
|
69 | - */ |
|
70 | - protected $_allowUnsecured; |
|
64 | + /** |
|
65 | + * Whether to allow unsecured JWT's, that is, claims without integrity |
|
66 | + * protection nor encryption. |
|
67 | + * |
|
68 | + * @var bool |
|
69 | + */ |
|
70 | + protected $_allowUnsecured; |
|
71 | 71 | |
72 | - /** |
|
73 | - * Constructor. |
|
74 | - * |
|
75 | - * @param null|array $constraints Optional array of constraints for the |
|
76 | - * registered claims |
|
77 | - * @param null|JWKSet $keys Optional set of JSON Web Keys used for |
|
78 | - * signature validation and/or decryption |
|
79 | - */ |
|
80 | - public function __construct(?array $constraints = null, ?JWKSet $keys = null) |
|
81 | - { |
|
82 | - $this->_refTime = time(); |
|
83 | - $this->_leeway = 60; |
|
84 | - $this->_constraints = $constraints ? $constraints : []; |
|
85 | - $this->_validators = []; |
|
86 | - $this->_keys = $keys ? $keys : new JWKSet(); |
|
87 | - $this->_allowUnsecured = false; |
|
88 | - } |
|
72 | + /** |
|
73 | + * Constructor. |
|
74 | + * |
|
75 | + * @param null|array $constraints Optional array of constraints for the |
|
76 | + * registered claims |
|
77 | + * @param null|JWKSet $keys Optional set of JSON Web Keys used for |
|
78 | + * signature validation and/or decryption |
|
79 | + */ |
|
80 | + public function __construct(?array $constraints = null, ?JWKSet $keys = null) |
|
81 | + { |
|
82 | + $this->_refTime = time(); |
|
83 | + $this->_leeway = 60; |
|
84 | + $this->_constraints = $constraints ? $constraints : []; |
|
85 | + $this->_validators = []; |
|
86 | + $this->_keys = $keys ? $keys : new JWKSet(); |
|
87 | + $this->_allowUnsecured = false; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Initialize with a single JSON Web Key. |
|
92 | - * |
|
93 | - * @param JWK $key JSON Web Key |
|
94 | - * @param null|array $constraints Optional constraints |
|
95 | - * |
|
96 | - * @return self |
|
97 | - */ |
|
98 | - public static function fromJWK(JWK $key, ?array $constraints = null): self |
|
99 | - { |
|
100 | - return new self($constraints, new JWKSet($key)); |
|
101 | - } |
|
90 | + /** |
|
91 | + * Initialize with a single JSON Web Key. |
|
92 | + * |
|
93 | + * @param JWK $key JSON Web Key |
|
94 | + * @param null|array $constraints Optional constraints |
|
95 | + * |
|
96 | + * @return self |
|
97 | + */ |
|
98 | + public static function fromJWK(JWK $key, ?array $constraints = null): self |
|
99 | + { |
|
100 | + return new self($constraints, new JWKSet($key)); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get self with the reference time. |
|
105 | - * |
|
106 | - * @param null|int $ts Unix timestamp |
|
107 | - * |
|
108 | - * @return self |
|
109 | - */ |
|
110 | - public function withReferenceTime(?int $ts): self |
|
111 | - { |
|
112 | - $obj = clone $this; |
|
113 | - $obj->_refTime = $ts; |
|
114 | - return $obj; |
|
115 | - } |
|
103 | + /** |
|
104 | + * Get self with the reference time. |
|
105 | + * |
|
106 | + * @param null|int $ts Unix timestamp |
|
107 | + * |
|
108 | + * @return self |
|
109 | + */ |
|
110 | + public function withReferenceTime(?int $ts): self |
|
111 | + { |
|
112 | + $obj = clone $this; |
|
113 | + $obj->_refTime = $ts; |
|
114 | + return $obj; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Check whether the reference time is set. |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function hasReferenceTime(): bool |
|
123 | - { |
|
124 | - return isset($this->_refTime); |
|
125 | - } |
|
117 | + /** |
|
118 | + * Check whether the reference time is set. |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function hasReferenceTime(): bool |
|
123 | + { |
|
124 | + return isset($this->_refTime); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Get the reference time. |
|
129 | - * |
|
130 | - * @throws \LogicException |
|
131 | - * |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function referenceTime(): int |
|
135 | - { |
|
136 | - if (!$this->hasReferenceTime()) { |
|
137 | - throw new \LogicException('Reference time not set.'); |
|
138 | - } |
|
139 | - return $this->_refTime; |
|
140 | - } |
|
127 | + /** |
|
128 | + * Get the reference time. |
|
129 | + * |
|
130 | + * @throws \LogicException |
|
131 | + * |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function referenceTime(): int |
|
135 | + { |
|
136 | + if (!$this->hasReferenceTime()) { |
|
137 | + throw new \LogicException('Reference time not set.'); |
|
138 | + } |
|
139 | + return $this->_refTime; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Get self with the reference time leeway. |
|
144 | - * |
|
145 | - * @param int $seconds |
|
146 | - * |
|
147 | - * @return self |
|
148 | - */ |
|
149 | - public function withLeeway(int $seconds): self |
|
150 | - { |
|
151 | - $obj = clone $this; |
|
152 | - $obj->_leeway = $seconds; |
|
153 | - return $obj; |
|
154 | - } |
|
142 | + /** |
|
143 | + * Get self with the reference time leeway. |
|
144 | + * |
|
145 | + * @param int $seconds |
|
146 | + * |
|
147 | + * @return self |
|
148 | + */ |
|
149 | + public function withLeeway(int $seconds): self |
|
150 | + { |
|
151 | + $obj = clone $this; |
|
152 | + $obj->_leeway = $seconds; |
|
153 | + return $obj; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Get the reference time leeway. |
|
158 | - * |
|
159 | - * @return int |
|
160 | - */ |
|
161 | - public function leeway(): int |
|
162 | - { |
|
163 | - return $this->_leeway; |
|
164 | - } |
|
156 | + /** |
|
157 | + * Get the reference time leeway. |
|
158 | + * |
|
159 | + * @return int |
|
160 | + */ |
|
161 | + public function leeway(): int |
|
162 | + { |
|
163 | + return $this->_leeway; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Get self with a validation constraint. |
|
168 | - * |
|
169 | - * If the claim does not provide its own validator, an explicit validator |
|
170 | - * must be given. |
|
171 | - * |
|
172 | - * @param string $name Claim name |
|
173 | - * @param mixed $constraint Value to check claim against |
|
174 | - * @param null|Validator $validator Optional explicit validator |
|
175 | - * |
|
176 | - * @return self |
|
177 | - */ |
|
178 | - public function withConstraint(string $name, $constraint, |
|
179 | - ?Validator $validator = null): self |
|
180 | - { |
|
181 | - $obj = clone $this; |
|
182 | - $obj->_constraints[$name] = $constraint; |
|
183 | - if ($validator) { |
|
184 | - $obj->_validators[$name] = $validator; |
|
185 | - } |
|
186 | - return $obj; |
|
187 | - } |
|
166 | + /** |
|
167 | + * Get self with a validation constraint. |
|
168 | + * |
|
169 | + * If the claim does not provide its own validator, an explicit validator |
|
170 | + * must be given. |
|
171 | + * |
|
172 | + * @param string $name Claim name |
|
173 | + * @param mixed $constraint Value to check claim against |
|
174 | + * @param null|Validator $validator Optional explicit validator |
|
175 | + * |
|
176 | + * @return self |
|
177 | + */ |
|
178 | + public function withConstraint(string $name, $constraint, |
|
179 | + ?Validator $validator = null): self |
|
180 | + { |
|
181 | + $obj = clone $this; |
|
182 | + $obj->_constraints[$name] = $constraint; |
|
183 | + if ($validator) { |
|
184 | + $obj->_validators[$name] = $validator; |
|
185 | + } |
|
186 | + return $obj; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Get self with the issuer constraint. |
|
191 | - * |
|
192 | - * @param string $issuer Issuer name |
|
193 | - * |
|
194 | - * @return self |
|
195 | - */ |
|
196 | - public function withIssuer(string $issuer): self |
|
197 | - { |
|
198 | - return $this->withConstraint(RegisteredClaim::NAME_ISSUER, $issuer); |
|
199 | - } |
|
189 | + /** |
|
190 | + * Get self with the issuer constraint. |
|
191 | + * |
|
192 | + * @param string $issuer Issuer name |
|
193 | + * |
|
194 | + * @return self |
|
195 | + */ |
|
196 | + public function withIssuer(string $issuer): self |
|
197 | + { |
|
198 | + return $this->withConstraint(RegisteredClaim::NAME_ISSUER, $issuer); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * Get self with the subject constraint. |
|
203 | - * |
|
204 | - * @param string $subject Subject name |
|
205 | - * |
|
206 | - * @return self |
|
207 | - */ |
|
208 | - public function withSubject(string $subject): self |
|
209 | - { |
|
210 | - return $this->withConstraint(RegisteredClaim::NAME_SUBJECT, $subject); |
|
211 | - } |
|
201 | + /** |
|
202 | + * Get self with the subject constraint. |
|
203 | + * |
|
204 | + * @param string $subject Subject name |
|
205 | + * |
|
206 | + * @return self |
|
207 | + */ |
|
208 | + public function withSubject(string $subject): self |
|
209 | + { |
|
210 | + return $this->withConstraint(RegisteredClaim::NAME_SUBJECT, $subject); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Get self with the audience constraint. |
|
215 | - * |
|
216 | - * @param string $audience Audience name |
|
217 | - * |
|
218 | - * @return self |
|
219 | - */ |
|
220 | - public function withAudience(string $audience): self |
|
221 | - { |
|
222 | - return $this->withConstraint(RegisteredClaim::NAME_AUDIENCE, $audience); |
|
223 | - } |
|
213 | + /** |
|
214 | + * Get self with the audience constraint. |
|
215 | + * |
|
216 | + * @param string $audience Audience name |
|
217 | + * |
|
218 | + * @return self |
|
219 | + */ |
|
220 | + public function withAudience(string $audience): self |
|
221 | + { |
|
222 | + return $this->withConstraint(RegisteredClaim::NAME_AUDIENCE, $audience); |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * Get self with the JWT ID constraint. |
|
227 | - * |
|
228 | - * @param string $id JWT ID |
|
229 | - * |
|
230 | - * @return self |
|
231 | - */ |
|
232 | - public function withID(string $id): self |
|
233 | - { |
|
234 | - return $this->withConstraint(RegisteredClaim::NAME_JWT_ID, $id); |
|
235 | - } |
|
225 | + /** |
|
226 | + * Get self with the JWT ID constraint. |
|
227 | + * |
|
228 | + * @param string $id JWT ID |
|
229 | + * |
|
230 | + * @return self |
|
231 | + */ |
|
232 | + public function withID(string $id): self |
|
233 | + { |
|
234 | + return $this->withConstraint(RegisteredClaim::NAME_JWT_ID, $id); |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Check whether a named constraint is present. |
|
239 | - * |
|
240 | - * @param string $name Claim name |
|
241 | - * |
|
242 | - * @return bool |
|
243 | - */ |
|
244 | - public function hasConstraint(string $name): bool |
|
245 | - { |
|
246 | - return isset($this->_constraints[$name]); |
|
247 | - } |
|
237 | + /** |
|
238 | + * Check whether a named constraint is present. |
|
239 | + * |
|
240 | + * @param string $name Claim name |
|
241 | + * |
|
242 | + * @return bool |
|
243 | + */ |
|
244 | + public function hasConstraint(string $name): bool |
|
245 | + { |
|
246 | + return isset($this->_constraints[$name]); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Get a constraint value by the claim name. |
|
251 | - * |
|
252 | - * @param string $name Claim name |
|
253 | - * |
|
254 | - * @throws \LogicException If constraint is not set |
|
255 | - * |
|
256 | - * @return mixed Constraint value |
|
257 | - */ |
|
258 | - public function constraint(string $name) |
|
259 | - { |
|
260 | - if (!$this->hasConstraint($name)) { |
|
261 | - throw new \LogicException("Constraint {$name} not set."); |
|
262 | - } |
|
263 | - return $this->_constraints[$name]; |
|
264 | - } |
|
249 | + /** |
|
250 | + * Get a constraint value by the claim name. |
|
251 | + * |
|
252 | + * @param string $name Claim name |
|
253 | + * |
|
254 | + * @throws \LogicException If constraint is not set |
|
255 | + * |
|
256 | + * @return mixed Constraint value |
|
257 | + */ |
|
258 | + public function constraint(string $name) |
|
259 | + { |
|
260 | + if (!$this->hasConstraint($name)) { |
|
261 | + throw new \LogicException("Constraint {$name} not set."); |
|
262 | + } |
|
263 | + return $this->_constraints[$name]; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Check whether a validator is defined for the given claim name. |
|
268 | - * |
|
269 | - * @param string $name Claim name |
|
270 | - * |
|
271 | - * @return bool |
|
272 | - */ |
|
273 | - public function hasValidator(string $name): bool |
|
274 | - { |
|
275 | - return isset($this->_validators[$name]); |
|
276 | - } |
|
266 | + /** |
|
267 | + * Check whether a validator is defined for the given claim name. |
|
268 | + * |
|
269 | + * @param string $name Claim name |
|
270 | + * |
|
271 | + * @return bool |
|
272 | + */ |
|
273 | + public function hasValidator(string $name): bool |
|
274 | + { |
|
275 | + return isset($this->_validators[$name]); |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Get explicitly defined validator by the claim name. |
|
280 | - * |
|
281 | - * @param string $name Claim name |
|
282 | - * |
|
283 | - * @throws \LogicException If validator is not set |
|
284 | - * |
|
285 | - * @return Validator |
|
286 | - */ |
|
287 | - public function validator(string $name): Validator |
|
288 | - { |
|
289 | - if (!$this->hasValidator($name)) { |
|
290 | - throw new \LogicException("Validator {$name} not set."); |
|
291 | - } |
|
292 | - return $this->_validators[$name]; |
|
293 | - } |
|
278 | + /** |
|
279 | + * Get explicitly defined validator by the claim name. |
|
280 | + * |
|
281 | + * @param string $name Claim name |
|
282 | + * |
|
283 | + * @throws \LogicException If validator is not set |
|
284 | + * |
|
285 | + * @return Validator |
|
286 | + */ |
|
287 | + public function validator(string $name): Validator |
|
288 | + { |
|
289 | + if (!$this->hasValidator($name)) { |
|
290 | + throw new \LogicException("Validator {$name} not set."); |
|
291 | + } |
|
292 | + return $this->_validators[$name]; |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Get a set of JSON Web Keys defined in this context. |
|
297 | - * |
|
298 | - * @return JWKSet |
|
299 | - */ |
|
300 | - public function keys(): JWKSet |
|
301 | - { |
|
302 | - return $this->_keys; |
|
303 | - } |
|
295 | + /** |
|
296 | + * Get a set of JSON Web Keys defined in this context. |
|
297 | + * |
|
298 | + * @return JWKSet |
|
299 | + */ |
|
300 | + public function keys(): JWKSet |
|
301 | + { |
|
302 | + return $this->_keys; |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * Get self with 'allow unsecured' flag set. |
|
307 | - * |
|
308 | - * If the unsecured JWT's are allowed, claims shall be considered valid even |
|
309 | - * though they are not signed nor encrypted. |
|
310 | - * |
|
311 | - * @param bool $allow Whether to allow unsecured JWT's |
|
312 | - * |
|
313 | - * @return self |
|
314 | - */ |
|
315 | - public function withUnsecuredAllowed(bool $allow): self |
|
316 | - { |
|
317 | - $obj = clone $this; |
|
318 | - $obj->_allowUnsecured = $allow; |
|
319 | - return $obj; |
|
320 | - } |
|
305 | + /** |
|
306 | + * Get self with 'allow unsecured' flag set. |
|
307 | + * |
|
308 | + * If the unsecured JWT's are allowed, claims shall be considered valid even |
|
309 | + * though they are not signed nor encrypted. |
|
310 | + * |
|
311 | + * @param bool $allow Whether to allow unsecured JWT's |
|
312 | + * |
|
313 | + * @return self |
|
314 | + */ |
|
315 | + public function withUnsecuredAllowed(bool $allow): self |
|
316 | + { |
|
317 | + $obj = clone $this; |
|
318 | + $obj->_allowUnsecured = $allow; |
|
319 | + return $obj; |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Check whether the unsecured JWT's are allowed. |
|
324 | - * |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function isUnsecuredAllowed(): bool |
|
328 | - { |
|
329 | - return $this->_allowUnsecured; |
|
330 | - } |
|
322 | + /** |
|
323 | + * Check whether the unsecured JWT's are allowed. |
|
324 | + * |
|
325 | + * @return bool |
|
326 | + */ |
|
327 | + public function isUnsecuredAllowed(): bool |
|
328 | + { |
|
329 | + return $this->_allowUnsecured; |
|
330 | + } |
|
331 | 331 | |
332 | - /** |
|
333 | - * Validate claims. |
|
334 | - * |
|
335 | - * @param Claims $claims |
|
336 | - * |
|
337 | - * @throws ValidationException If any of the claims is not valid |
|
338 | - * |
|
339 | - * @return self |
|
340 | - */ |
|
341 | - public function validate(Claims $claims): self |
|
342 | - { |
|
343 | - foreach ($claims as $claim) { |
|
344 | - if (!$claim->validateWithContext($this)) { |
|
345 | - throw new ValidationException( |
|
346 | - "Validation of claim '" . $claim->name() . "' failed."); |
|
347 | - } |
|
348 | - } |
|
349 | - return $this; |
|
350 | - } |
|
332 | + /** |
|
333 | + * Validate claims. |
|
334 | + * |
|
335 | + * @param Claims $claims |
|
336 | + * |
|
337 | + * @throws ValidationException If any of the claims is not valid |
|
338 | + * |
|
339 | + * @return self |
|
340 | + */ |
|
341 | + public function validate(Claims $claims): self |
|
342 | + { |
|
343 | + foreach ($claims as $claim) { |
|
344 | + if (!$claim->validateWithContext($this)) { |
|
345 | + throw new ValidationException( |
|
346 | + "Validation of claim '" . $claim->name() . "' failed."); |
|
347 | + } |
|
348 | + } |
|
349 | + return $this; |
|
350 | + } |
|
351 | 351 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT; |
6 | 6 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\JWT\Exception; |
6 | 6 |
@@ -12,54 +12,54 @@ |
||
12 | 12 | */ |
13 | 13 | trait Base64URLValue |
14 | 14 | { |
15 | - use StringParameterValue; |
|
15 | + use StringParameterValue; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Get the parameter value. |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - abstract public function value(); |
|
17 | + /** |
|
18 | + * Get the parameter value. |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + abstract public function value(); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Initialize from native value. |
|
26 | - * |
|
27 | - * Value shall be encoded using Base64url encoding. |
|
28 | - * |
|
29 | - * @param string $value |
|
30 | - * |
|
31 | - * @return self |
|
32 | - */ |
|
33 | - public static function fromString(string $value): Parameter |
|
34 | - { |
|
35 | - return new static(Base64::urlEncode($value)); |
|
36 | - } |
|
24 | + /** |
|
25 | + * Initialize from native value. |
|
26 | + * |
|
27 | + * Value shall be encoded using Base64url encoding. |
|
28 | + * |
|
29 | + * @param string $value |
|
30 | + * |
|
31 | + * @return self |
|
32 | + */ |
|
33 | + public static function fromString(string $value): Parameter |
|
34 | + { |
|
35 | + return new static(Base64::urlEncode($value)); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the parameter value as a decoded string. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function string(): string |
|
44 | - { |
|
45 | - return Base64::urlDecode($this->value()); |
|
46 | - } |
|
38 | + /** |
|
39 | + * Get the parameter value as a decoded string. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function string(): string |
|
44 | + { |
|
45 | + return Base64::urlDecode($this->value()); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Validate that value is validly base64url encoded. |
|
50 | - * |
|
51 | - * @param string $value |
|
52 | - * |
|
53 | - * @throws \UnexpectedValueException |
|
54 | - * |
|
55 | - * @return self |
|
56 | - */ |
|
57 | - protected function _validateEncoding(string $value) |
|
58 | - { |
|
59 | - if (!Base64::isValidURLEncoding($value)) { |
|
60 | - throw new \UnexpectedValueException( |
|
61 | - 'Value must be base64url encoded.'); |
|
62 | - } |
|
63 | - return $this; |
|
64 | - } |
|
48 | + /** |
|
49 | + * Validate that value is validly base64url encoded. |
|
50 | + * |
|
51 | + * @param string $value |
|
52 | + * |
|
53 | + * @throws \UnexpectedValueException |
|
54 | + * |
|
55 | + * @return self |
|
56 | + */ |
|
57 | + protected function _validateEncoding(string $value) |
|
58 | + { |
|
59 | + if (!Base64::isValidURLEncoding($value)) { |
|
60 | + throw new \UnexpectedValueException( |
|
61 | + 'Value must be base64url encoded.'); |
|
62 | + } |
|
63 | + return $this; |
|
64 | + } |
|
65 | 65 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\JWX\Parameter\Feature; |
6 | 6 |