GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 356550...41f07f )
by sebastian
03:01
created
src/jws/impl/JWS.php 2 patches
Spacing   +39 added lines, -51 removed lines patch added patch discarded remove patch
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 
73 73
         $claim_set = null;
74 74
 
75
-        if(!is_null($payload) && $payload->isClaimSet() && $payload instanceof IJWSPayloadClaimSetSpec) {
75
+        if (!is_null($payload) && $payload->isClaimSet() && $payload instanceof IJWSPayloadClaimSetSpec) {
76 76
             $header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::Type, new StringOrURI('JWT')));
77 77
             $claim_set = $payload->getClaimSet();
78 78
         }
79 79
 
80 80
         parent::__construct($header, $claim_set);
81 81
 
82
-        if(!is_null($payload))
82
+        if (!is_null($payload))
83 83
             $this->setPayload($payload);
84 84
 
85 85
         $this->signature = $signature;
@@ -100,21 +100,18 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function toCompactSerialization()
102 102
     {
103
-        if(!is_null($this->jwk->getId()))
103
+        if (!is_null($this->jwk->getId()))
104 104
             $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId()));
105 105
 
106
-        if($this->jwk instanceof IAsymmetricJWK)
106
+        if ($this->jwk instanceof IAsymmetricJWK)
107 107
         {
108 108
             // we should add the public key on the header
109 109
             $public_key = clone $this->jwk;
110 110
 
111
-            $this->header->addHeader
112
-            (
113
-                new JOSEHeaderParam
114
-                (
111
+            $this->header->addHeader(
112
+                new JOSEHeaderParam(
115 113
                     RegisteredJOSEHeaderNames::JSONWebKey,
116
-                    new JsonValue
117
-                    (
114
+                    new JsonValue(
118 115
                         $public_key->setVisibility(JSONWebKeyVisibility::PublicOnly)
119 116
                     )
120 117
                 )
@@ -134,32 +131,32 @@  discard block
 block discarded – undo
134 131
     public function sign()
135 132
     {
136 133
 
137
-        if(is_null($this->jwk))
134
+        if (is_null($this->jwk))
138 135
             throw new JWSInvalidJWKException;
139 136
 
140
-        if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature)
137
+        if ($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature)
141 138
             throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString()));
142 139
 
143 140
         $alg = DigitalSignatures_MACs_Registry::getInstance()->get($this->header->getAlgorithm()->getString());
144 141
 
145
-        if(is_null($alg))
146
-            throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString()));
142
+        if (is_null($alg))
143
+            throw new JWSNotSupportedAlgorithm(sprintf('alg %s.', $this->header->getAlgorithm()->getString()));
147 144
 
148
-        $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload();
145
+        $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header).IBasicJWT::SegmentSeparator.$this->getEncodedPayload();
149 146
 
150
-        $key  = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC);
147
+        $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC);
151 148
 
152
-        if($alg instanceof DigitalSignatureAlgorithm)
149
+        if ($alg instanceof DigitalSignatureAlgorithm)
153 150
         {
154 151
             $this->signature = $alg->sign($key, $secured_input_bytes);
155 152
         }
156
-        else if($alg instanceof MAC_Algorithm )
153
+        else if ($alg instanceof MAC_Algorithm)
157 154
         {
158 155
             $this->signature = $alg->digest($key, $secured_input_bytes);
159 156
         }
160 157
         else
161 158
         {
162
-            throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString()));
159
+            throw new JWSNotSupportedAlgorithm(sprintf('alg %s.', $this->header->getAlgorithm()->getString()));
163 160
         }
164 161
 
165 162
         return $this;
@@ -171,16 +168,16 @@  discard block
 block discarded – undo
171 168
      */
172 169
     public function getEncodedPayload()
173 170
     {
174
-        if(is_null($this->payload))
171
+        if (is_null($this->payload))
175 172
             throw new JWSInvalidPayloadException('payload is not set!');
176 173
 
177 174
         $enc_payload = '';
178 175
 
179
-        if($this->payload instanceof IJWSPayloadClaimSetSpec)
176
+        if ($this->payload instanceof IJWSPayloadClaimSetSpec)
180 177
         {
181 178
             $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet());
182 179
         }
183
-        else if($this->payload instanceof IJWSPayloadRawSpec)
180
+        else if ($this->payload instanceof IJWSPayloadRawSpec)
184 181
         {
185 182
             $enc_payload = JWTRawSerializer::serialize($this->payload->getRaw());
186 183
         }
@@ -234,27 +231,23 @@  discard block
 block discarded – undo
234 231
      */
235 232
     public function verify($original_alg)
236 233
     {
237
-        if(is_null($this->jwk))
234
+        if (is_null($this->jwk))
238 235
             throw new JWSInvalidJWKException;
239 236
 
240
-        if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature)
241
-            throw new JWSInvalidJWKException
242
-            (
243
-                sprintf
244
-                (
237
+        if ($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature)
238
+            throw new JWSInvalidJWKException(
239
+                sprintf(
245 240
                     'use %s not supported ',
246 241
                     $this->jwk->getKeyUse()->getString()
247 242
                 )
248 243
             );
249 244
 
250
-        if(is_null($this->jwk->getAlgorithm()))
245
+        if (is_null($this->jwk->getAlgorithm()))
251 246
             throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! ');
252 247
 
253
-        if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue())
254
-            throw new JWSInvalidJWKException
255
-            (
256
-                sprintf
257
-                (
248
+        if (!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue())
249
+            throw new JWSInvalidJWKException(
250
+                sprintf(
258 251
                     'original kid %s - current kid %s',
259 252
                     $this->header->getKeyID()->getValue(),
260 253
                     $this->jwk->getId()->getValue()
@@ -263,34 +256,30 @@  discard block
 block discarded – undo
263 256
 
264 257
         $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg);
265 258
 
266
-        if(is_null($alg))
259
+        if (is_null($alg))
267 260
             throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg));
268 261
 
269 262
         $former_alg = $this->header->getAlgorithm()->getString();
270 263
 
271
-        if($former_alg != $original_alg)
272
-            throw new JWSNotSupportedAlgorithm
273
-            (
274
-                sprintf
275
-                (
264
+        if ($former_alg != $original_alg)
265
+            throw new JWSNotSupportedAlgorithm(
266
+                sprintf(
276 267
                     'former alg %s - original alg %s',
277 268
                     $former_alg,
278 269
                     $original_alg
279 270
                 )
280 271
             );
281 272
 
282
-        if($this->jwk->getAlgorithm()->getValue() !==  $original_alg)
283
-            throw new InvalidJWKAlgorithm
284
-            (
285
-                sprintf
286
-                (
273
+        if ($this->jwk->getAlgorithm()->getValue() !== $original_alg)
274
+            throw new InvalidJWKAlgorithm(
275
+                sprintf(
287 276
                     'mismatch between algorithm intended for use with the key %s and the cryptographic algorithm used to secure the JWS %s',
288 277
                     $this->jwk->getAlgorithm()->getValue(),
289 278
                     $original_alg
290 279
                 )
291 280
             );
292 281
 
293
-        $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload();
282
+        $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header).IBasicJWT::SegmentSeparator.$this->getEncodedPayload();
294 283
 
295 284
         // use public key / secret
296 285
         $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::VerifyDigitalSignatureOrMAC);
@@ -311,9 +300,9 @@  discard block
 block discarded – undo
311 300
      * @param string $signature
312 301
      * @return IJWS
313 302
      */
314
-    static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null , $signature = '')
303
+    static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null, $signature = '')
315 304
     {
316
-        return new JWS($header, $payload, $signature );
305
+        return new JWS($header, $payload, $signature);
317 306
     }
318 307
 
319 308
     /**
@@ -321,9 +310,8 @@  discard block
 block discarded – undo
321 310
      */
322 311
     public function take()
323 312
     {
324
-        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ?  $this->payload->getRaw() : $this->claim_set;
325
-        return array
326
-        (
313
+        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw() : $this->claim_set;
314
+        return array(
327 315
             $this->header,
328 316
             $payload,
329 317
             $this->signature
Please login to merge, or discard this patch.
Braces   +42 added lines, -32 removed lines patch added patch discarded remove patch
@@ -79,8 +79,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,16 +174,16 @@  discard block
 block discarded – undo
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
 
179 183
         if($this->payload instanceof IJWSPayloadClaimSetSpec)
180 184
         {
181 185
             $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet());
182
-        }
183
-        else if($this->payload instanceof IJWSPayloadRawSpec)
186
+        } else if($this->payload instanceof IJWSPayloadRawSpec)
184 187
         {
185 188
             $enc_payload = JWTRawSerializer::serialize($this->payload->getRaw());
186 189
         }
@@ -234,11 +237,12 @@  discard block
 block discarded – undo
234 237
      */
235 238
     public function verify($original_alg)
236 239
     {
237
-        if(is_null($this->jwk))
238
-            throw new JWSInvalidJWKException;
240
+        if(is_null($this->jwk)) {
241
+                    throw new JWSInvalidJWKException;
242
+        }
239 243
 
240
-        if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature)
241
-            throw new JWSInvalidJWKException
244
+        if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) {
245
+                    throw new JWSInvalidJWKException
242 246
             (
243 247
                 sprintf
244 248
                 (
@@ -246,12 +250,14 @@  discard block
 block discarded – undo
246 250
                     $this->jwk->getKeyUse()->getString()
247 251
                 )
248 252
             );
253
+        }
249 254
 
250
-        if(is_null($this->jwk->getAlgorithm()))
251
-            throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! ');
255
+        if(is_null($this->jwk->getAlgorithm())) {
256
+                    throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! ');
257
+        }
252 258
 
253
-        if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue())
254
-            throw new JWSInvalidJWKException
259
+        if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) {
260
+                    throw new JWSInvalidJWKException
255 261
             (
256 262
                 sprintf
257 263
                 (
@@ -260,16 +266,18 @@  discard block
 block discarded – undo
260 266
                     $this->jwk->getId()->getValue()
261 267
                 )
262 268
             );
269
+        }
263 270
 
264 271
         $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg);
265 272
 
266
-        if(is_null($alg))
267
-            throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg));
273
+        if(is_null($alg)) {
274
+                    throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg));
275
+        }
268 276
 
269 277
         $former_alg = $this->header->getAlgorithm()->getString();
270 278
 
271
-        if($former_alg != $original_alg)
272
-            throw new JWSNotSupportedAlgorithm
279
+        if($former_alg != $original_alg) {
280
+                    throw new JWSNotSupportedAlgorithm
273 281
             (
274 282
                 sprintf
275 283
                 (
@@ -278,9 +286,10 @@  discard block
 block discarded – undo
278 286
                     $original_alg
279 287
                 )
280 288
             );
289
+        }
281 290
 
282
-        if($this->jwk->getAlgorithm()->getValue() !==  $original_alg)
283
-            throw new InvalidJWKAlgorithm
291
+        if($this->jwk->getAlgorithm()->getValue() !==  $original_alg) {
292
+                    throw new InvalidJWKAlgorithm
284 293
             (
285 294
                 sprintf
286 295
                 (
@@ -289,6 +298,7 @@  discard block
 block discarded – undo
289 298
                     $original_alg
290 299
                 )
291 300
             );
301
+        }
292 302
 
293 303
         $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload();
294 304
 
Please login to merge, or discard this patch.