@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | |
42 | 42 | if($spec instanceof IJWS_ParamsSpecification) |
43 | 43 | { |
44 | - if($spec->getKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
45 | - throw new InvalidJWKType |
|
44 | + if($spec->getKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) { |
|
45 | + throw new InvalidJWKType |
|
46 | 46 | ( |
47 | 47 | sprintf |
48 | 48 | ( |
@@ -50,9 +50,10 @@ discard block |
||
50 | 50 | $spec->getKey()->getKeyUse()->getString() |
51 | 51 | ) |
52 | 52 | ); |
53 | + } |
|
53 | 54 | |
54 | - if($spec->getAlg()->getString() !== $spec->getKey()->getAlgorithm()->getString()) |
|
55 | - throw new InvalidJWKAlgorithm |
|
55 | + if($spec->getAlg()->getString() !== $spec->getKey()->getAlgorithm()->getString()) { |
|
56 | + throw new InvalidJWKAlgorithm |
|
56 | 57 | ( |
57 | 58 | sprintf |
58 | 59 | ( |
@@ -61,6 +62,7 @@ discard block |
||
61 | 62 | $spec->getKey()->getAlgorithm()->getString() |
62 | 63 | ) |
63 | 64 | ); |
65 | + } |
|
64 | 66 | |
65 | 67 | $header = new JOSEHeader |
66 | 68 | ( |
@@ -56,11 +56,13 @@ |
||
56 | 56 | */ |
57 | 57 | public function __construct(IJWK $key, StringOrURI $alg, $payload, $signature = ''){ |
58 | 58 | |
59 | - if(is_null($key)) |
|
60 | - throw new InvalidJWKType(); |
|
59 | + if(is_null($key)) { |
|
60 | + throw new InvalidJWKType(); |
|
61 | + } |
|
61 | 62 | |
62 | - if(is_null($payload)) |
|
63 | - throw new JWSInvalidPayloadException('missing payload'); |
|
63 | + if(is_null($payload)) { |
|
64 | + throw new JWSInvalidPayloadException('missing payload'); |
|
65 | + } |
|
64 | 66 | |
65 | 67 | $this->key = $key; |
66 | 68 | $this->alg = $alg; |
@@ -79,8 +79,9 @@ discard block |
||
79 | 79 | |
80 | 80 | parent::__construct($header, $claim_set); |
81 | 81 | |
82 | - if(!is_null($payload)) |
|
83 | - $this->setPayload($payload); |
|
82 | + if(!is_null($payload)) { |
|
83 | + $this->setPayload($payload); |
|
84 | + } |
|
84 | 85 | |
85 | 86 | $this->signature = $signature; |
86 | 87 | } |
@@ -100,8 +101,9 @@ discard block |
||
100 | 101 | */ |
101 | 102 | public function toCompactSerialization() |
102 | 103 | { |
103 | - if(!is_null($this->jwk->getId())) |
|
104 | - $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId())); |
|
104 | + if(!is_null($this->jwk->getId())) { |
|
105 | + $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId())); |
|
106 | + } |
|
105 | 107 | |
106 | 108 | if($this->jwk instanceof IAsymmetricJWK) |
107 | 109 | { |
@@ -134,16 +136,19 @@ discard block |
||
134 | 136 | public function sign() |
135 | 137 | { |
136 | 138 | |
137 | - if(is_null($this->jwk)) |
|
138 | - throw new JWSInvalidJWKException; |
|
139 | + if(is_null($this->jwk)) { |
|
140 | + throw new JWSInvalidJWKException; |
|
141 | + } |
|
139 | 142 | |
140 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
141 | - throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString())); |
|
143 | + if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) { |
|
144 | + throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString())); |
|
145 | + } |
|
142 | 146 | |
143 | 147 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($this->header->getAlgorithm()->getString()); |
144 | 148 | |
145 | - if(is_null($alg)) |
|
146 | - throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
149 | + if(is_null($alg)) { |
|
150 | + throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
151 | + } |
|
147 | 152 | |
148 | 153 | $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
149 | 154 | |
@@ -152,12 +157,10 @@ discard block |
||
152 | 157 | if($alg instanceof DigitalSignatureAlgorithm) |
153 | 158 | { |
154 | 159 | $this->signature = $alg->sign($key, $secured_input_bytes); |
155 | - } |
|
156 | - else if($alg instanceof MAC_Algorithm ) |
|
160 | + } else if($alg instanceof MAC_Algorithm ) |
|
157 | 161 | { |
158 | 162 | $this->signature = $alg->digest($key, $secured_input_bytes); |
159 | - } |
|
160 | - else |
|
163 | + } else |
|
161 | 164 | { |
162 | 165 | throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
163 | 166 | } |
@@ -171,15 +174,15 @@ discard block |
||
171 | 174 | */ |
172 | 175 | public function getEncodedPayload() |
173 | 176 | { |
174 | - if(is_null($this->payload)) |
|
175 | - throw new JWSInvalidPayloadException('payload is not set!'); |
|
177 | + if(is_null($this->payload)) { |
|
178 | + throw new JWSInvalidPayloadException('payload is not set!'); |
|
179 | + } |
|
176 | 180 | |
177 | 181 | $enc_payload = ''; |
178 | 182 | if($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) |
179 | 183 | { |
180 | 184 | $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet()); |
181 | - } |
|
182 | - else |
|
185 | + } else |
|
183 | 186 | { |
184 | 187 | $enc_payload = JWTRawSerializer::serialize($this->payload->getRaw()); |
185 | 188 | } |
@@ -233,11 +236,12 @@ discard block |
||
233 | 236 | */ |
234 | 237 | public function verify($original_alg) |
235 | 238 | { |
236 | - if(is_null($this->jwk)) |
|
237 | - throw new JWSInvalidJWKException; |
|
239 | + if(is_null($this->jwk)) { |
|
240 | + throw new JWSInvalidJWKException; |
|
241 | + } |
|
238 | 242 | |
239 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
240 | - throw new JWSInvalidJWKException |
|
243 | + if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) { |
|
244 | + throw new JWSInvalidJWKException |
|
241 | 245 | ( |
242 | 246 | sprintf |
243 | 247 | ( |
@@ -245,12 +249,14 @@ discard block |
||
245 | 249 | $this->jwk->getKeyUse()->getString() |
246 | 250 | ) |
247 | 251 | ); |
252 | + } |
|
248 | 253 | |
249 | - if(is_null($this->jwk->getAlgorithm())) |
|
250 | - throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
|
254 | + if(is_null($this->jwk->getAlgorithm())) { |
|
255 | + throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
|
256 | + } |
|
251 | 257 | |
252 | - if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
253 | - throw new JWSInvalidJWKException |
|
258 | + if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) { |
|
259 | + throw new JWSInvalidJWKException |
|
254 | 260 | ( |
255 | 261 | sprintf |
256 | 262 | ( |
@@ -259,16 +265,18 @@ discard block |
||
259 | 265 | $this->jwk->getId()->getValue() |
260 | 266 | ) |
261 | 267 | ); |
268 | + } |
|
262 | 269 | |
263 | 270 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg); |
264 | 271 | |
265 | - if(is_null($alg)) |
|
266 | - throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
|
272 | + if(is_null($alg)) { |
|
273 | + throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
|
274 | + } |
|
267 | 275 | |
268 | 276 | $former_alg = $this->header->getAlgorithm()->getString(); |
269 | 277 | |
270 | - if($former_alg != $original_alg) |
|
271 | - throw new JWSNotSupportedAlgorithm |
|
278 | + if($former_alg != $original_alg) { |
|
279 | + throw new JWSNotSupportedAlgorithm |
|
272 | 280 | ( |
273 | 281 | sprintf |
274 | 282 | ( |
@@ -277,9 +285,10 @@ discard block |
||
277 | 285 | $original_alg |
278 | 286 | ) |
279 | 287 | ); |
288 | + } |
|
280 | 289 | |
281 | - if($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
282 | - throw new InvalidJWKAlgorithm |
|
290 | + if($this->jwk->getAlgorithm()->getValue() !== $original_alg) { |
|
291 | + throw new InvalidJWKAlgorithm |
|
283 | 292 | ( |
284 | 293 | sprintf |
285 | 294 | ( |
@@ -288,6 +297,7 @@ discard block |
||
288 | 297 | $original_alg |
289 | 298 | ) |
290 | 299 | ); |
300 | + } |
|
291 | 301 | |
292 | 302 | $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
293 | 303 |
@@ -33,8 +33,7 @@ |
||
33 | 33 | |
34 | 34 | if($content instanceof IJWTClaimSet){ |
35 | 35 | return new _JWSPayloadClaimSetSpec($content); |
36 | - } |
|
37 | - else{ |
|
36 | + } else{ |
|
38 | 37 | return new _JWSPayloadRawSpec($content); |
39 | 38 | } |
40 | 39 | } |
@@ -29,7 +29,9 @@ |
||
29 | 29 | */ |
30 | 30 | public function invoke() |
31 | 31 | { |
32 | - if(func_num_args() <= 0) throw new \RuntimeException('you must pass len as arg!'); |
|
32 | + if(func_num_args() <= 0) { |
|
33 | + throw new \RuntimeException('you must pass len as arg!'); |
|
34 | + } |
|
33 | 35 | $byte_len = func_get_arg(0); |
34 | 36 | return ByteUtil::randomBytes($byte_len); |
35 | 37 | } |
@@ -54,8 +54,9 @@ |
||
54 | 54 | * @return null|IService |
55 | 55 | */ |
56 | 56 | public function get($service_name){ |
57 | - if(!array_key_exists($service_name, $this->services)) |
|
58 | - throw new \InvalidArgumentException('unknown service!'); |
|
57 | + if(!array_key_exists($service_name, $this->services)) { |
|
58 | + throw new \InvalidArgumentException('unknown service!'); |
|
59 | + } |
|
59 | 60 | |
60 | 61 | return $this->services[$service_name]; |
61 | 62 | } |
@@ -47,8 +47,9 @@ |
||
47 | 47 | case 3: |
48 | 48 | // JWS or unsecured one |
49 | 49 | $header = JOSEHeaderSerializer::deserialize($segments[0]); |
50 | - if($header->getAlgorithm()->getString() === 'none' && empty($segments[2])) |
|
51 | - return UnsecuredJWT::fromCompactSerialization($compact_serialization); |
|
50 | + if($header->getAlgorithm()->getString() === 'none' && empty($segments[2])) { |
|
51 | + return UnsecuredJWT::fromCompactSerialization($compact_serialization); |
|
52 | + } |
|
52 | 53 | return JWSFactory::build( new JWS_CompactFormatSpecification($compact_serialization) ); |
53 | 54 | break; |
54 | 55 | case 5: |
@@ -35,10 +35,12 @@ |
||
35 | 35 | */ |
36 | 36 | public function getUri(){ |
37 | 37 | |
38 | - if($this->isString()) |
|
39 | - throw new \RuntimeException('current value is not an uri!'); |
|
40 | - if(filter_var($this->value, FILTER_VALIDATE_URL) === false) |
|
41 | - throw new \RuntimeException('current value is not an uri!'); |
|
38 | + if($this->isString()) { |
|
39 | + throw new \RuntimeException('current value is not an uri!'); |
|
40 | + } |
|
41 | + if(filter_var($this->value, FILTER_VALIDATE_URL) === false) { |
|
42 | + throw new \RuntimeException('current value is not an uri!'); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | return (string)$this->value; |
44 | 46 | } |
@@ -41,8 +41,9 @@ |
||
41 | 41 | |
42 | 42 | public function offsetUnset($offset) |
43 | 43 | { |
44 | - if ($this->offsetExists($offset)) |
|
45 | - unset($this->value[$offset]); |
|
44 | + if ($this->offsetExists($offset)) { |
|
45 | + unset($this->value[$offset]); |
|
46 | + } |
|
46 | 47 | } |
47 | 48 | |
48 | 49 | public function append($value){ |