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
Branch master (356550)
by sebastian
02:47
created
src/jwe/impl/JWE.php 1 patch
Spacing   +40 added lines, -60 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     protected function __construct(IJWEJOSEHeader $header, IJWSPayloadSpec $payload = null)
98 98
     {
99 99
         $this->header = $header;
100
-        if(!is_null($payload))
100
+        if (!is_null($payload))
101 101
             $this->setPayload($payload);
102 102
     }
103 103
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         if (is_null($this->payload))
158 158
             $this->payload = JWSPayloadFactory::build('');
159 159
 
160
-        return ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw():'';
160
+        return ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw() : '';
161 161
     }
162 162
 
163 163
     /**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
          * the result be the JWE Encrypted Key.
183 183
          */
184 184
          $key_management_mode = $this->getKeyManagementMode($alg);
185
-         switch($key_management_mode){
185
+         switch ($key_management_mode) {
186 186
              case KeyManagementModeValues::KeyEncryption:
187 187
              case KeyManagementModeValues::KeyWrapping:
188 188
              case KeyManagementModeValues::KeyAgreementWithKeyWrapping:
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
      */
209 209
     private function getKeyManagementMode(EncryptionAlgorithm $alg)
210 210
     {
211
-        if($alg instanceof KeyEncryption)
211
+        if ($alg instanceof KeyEncryption)
212 212
             return KeyManagementModeValues::KeyEncryption;
213
-        if($alg instanceof KeyWrapping)
213
+        if ($alg instanceof KeyWrapping)
214 214
             return KeyManagementModeValues::KeyWrapping;
215
-        if($alg instanceof DirectKeyAgreement)
215
+        if ($alg instanceof DirectKeyAgreement)
216 216
             return KeyManagementModeValues::DirectKeyAgreement;
217
-        if($alg instanceof KeyAgreementWithKeyWrapping)
217
+        if ($alg instanceof KeyAgreementWithKeyWrapping)
218 218
             return KeyManagementModeValues::KeyAgreementWithKeyWrapping;
219
-        if($alg instanceof DirectEncryption)
219
+        if ($alg instanceof DirectEncryption)
220 220
             return KeyManagementModeValues::DirectEncryption;
221 221
     }
222 222
 
@@ -235,11 +235,9 @@  discard block
 block discarded – undo
235 235
         if (is_null($this->jwk))
236 236
             throw new JWEInvalidRecipientKeyException;
237 237
 
238
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
239
-            throw new InvalidJWKAlgorithm
240
-            (
241
-                sprintf
242
-                (
238
+        if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString())
239
+            throw new InvalidJWKAlgorithm(
240
+                sprintf(
243 241
                     'mismatch between algorithm intended for use with the key %s and the cryptographic algorithm used to encrypt or determine the value of the CEK %s',
244 242
                     $this->jwk->getAlgorithm()->getValue(),
245 243
                     $this->header->getAlgorithm()->getString()
@@ -253,27 +251,22 @@  discard block
 block discarded – undo
253 251
         if (is_null($key_management_algorithm))
254 252
             throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString()));
255 253
 
256
-        if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm())
257
-            throw new InvalidKeyTypeAlgorithmException
258
-            (
259
-                sprintf
260
-                (
254
+        if ($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm())
255
+            throw new InvalidKeyTypeAlgorithmException(
256
+                sprintf(
261 257
                     'key should be for alg %s, %s instead.',
262 258
                     $key_management_algorithm->getKeyType(),
263 259
                     $recipient_public_key->getAlgorithm()
264 260
                 )
265 261
             );
266 262
 
267
-        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
268
-        (
263
+        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get(
269 264
             $this->header->getEncryptionAlgorithm()->getString()
270 265
         );
271 266
 
272 267
         if (is_null($content_encryption_algorithm))
273
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
274
-            (
275
-                sprintf
276
-                (
268
+            throw new JWEUnsupportedContentEncryptionAlgorithmException(
269
+                sprintf(
277 270
                     'enc %s',
278 271
                     $this->header->getEncryptionAlgorithm()->getString()
279 272
                 )
@@ -281,8 +274,7 @@  discard block
 block discarded – undo
281 274
 
282 275
         $key_management_mode = $this->getKeyManagementMode($key_management_algorithm);
283 276
 
284
-        $this->cek     = ContentEncryptionKeyFactory::build
285
-        (
277
+        $this->cek = ContentEncryptionKeyFactory::build(
286 278
             $recipient_public_key,
287 279
             $key_management_mode,
288 280
             $content_encryption_algorithm
@@ -296,7 +288,7 @@  discard block
 block discarded – undo
296 288
          * algorithm); otherwise, let the JWE Initialization Vector be the
297 289
          * empty octet sequence.
298 290
          */
299
-        $this->iv      = '';
291
+        $this->iv = '';
300 292
 
301 293
         if (!is_null($iv_size = $content_encryption_algorithm->getIVSize()))
302 294
         {
@@ -305,7 +297,7 @@  discard block
 block discarded – undo
305 297
         // We encrypt the payload and get the tag
306 298
         $jwt_shared_protected_header = JOSEHeaderSerializer::serialize($this->header);
307 299
 
308
-        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw():'';
300
+        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw() : '';
309 301
         $zip     = $this->header->getCompressionAlgorithm();
310 302
         /**
311 303
          * If a "zip" parameter was included, compress the plaintext using
@@ -313,10 +305,10 @@  discard block
 block discarded – undo
313 305
          * sequence representing the compressed plaintext; otherwise, let M
314 306
          * be the octet sequence representing the plaintext.
315 307
          */
316
-        if(!is_null($zip))
308
+        if (!is_null($zip))
317 309
         {
318 310
             $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue());
319
-            $payload  = $compression__algorithm->compress($payload);
311
+            $payload = $compression__algorithm->compress($payload);
320 312
         }
321 313
 
322 314
         /**
@@ -326,8 +318,7 @@  discard block
 block discarded – undo
326 318
          * JWE Authentication Tag (which is the Authentication Tag output
327 319
          * from the encryption operation).
328 320
          */
329
-        list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt
330
-        (
321
+        list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt(
331 322
             $payload,
332 323
             $this->cek->getEncoded(),
333 324
             $this->iv,
@@ -345,23 +336,21 @@  discard block
 block discarded – undo
345 336
      * @throws InvalidKeyTypeAlgorithmException
346 337
      * @throws \Exception
347 338
      */
348
-    private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg){
339
+    private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg) {
349 340
 
350 341
         $key_management_mode   = $this->getKeyManagementMode($alg);
351 342
         $recipient_private_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption);
352 343
 
353
-        if($alg->getKeyType() !== $recipient_private_key->getAlgorithm())
354
-            throw new InvalidKeyTypeAlgorithmException
355
-            (
356
-                sprintf
357
-                (
344
+        if ($alg->getKeyType() !== $recipient_private_key->getAlgorithm())
345
+            throw new InvalidKeyTypeAlgorithmException(
346
+                sprintf(
358 347
                     'key should be for alg %s, %s instead.',
359 348
                     $alg->getKeyType(),
360 349
                     $recipient_private_key->getAlgorithm()
361 350
                 )
362 351
             );
363 352
 
364
-        switch($key_management_mode){
353
+        switch ($key_management_mode) {
365 354
             /**
366 355
              * When Key Wrapping, Key Encryption, or Key Agreement with Key
367 356
              * Wrapping are employed, decrypt the JWE Encrypted Key to produce
@@ -414,42 +403,34 @@  discard block
 block discarded – undo
414 403
 
415 404
         if (!$this->should_decrypt) return $this;
416 405
 
417
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
418
-            throw new InvalidJWKAlgorithm
419
-            (
420
-                sprintf
421
-                (
406
+        if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString())
407
+            throw new InvalidJWKAlgorithm(
408
+                sprintf(
422 409
                     'mismatch between algorithm intended for use with the key %s and the cryptographic algorithm used to encrypt or determine the value of the CEK %s',
423 410
                     $this->jwk->getAlgorithm()->getValue(),
424 411
                     $this->header->getAlgorithm()->getString()
425 412
                 )
426 413
             );
427 414
 
428
-        $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get
429
-        (
415
+        $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get(
430 416
             $this->header->getAlgorithm()->getString()
431 417
         );
432 418
 
433 419
         if (is_null($key_management_algorithm))
434
-            throw new JWEUnsupportedKeyManagementAlgorithmException
435
-            (
436
-                sprintf
437
-                (
420
+            throw new JWEUnsupportedKeyManagementAlgorithmException(
421
+                sprintf(
438 422
                     'alg %s',
439 423
                     $this->header->getAlgorithm()->getString()
440 424
                 )
441 425
             );
442 426
 
443
-        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
444
-        (
427
+        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get(
445 428
             $this->header->getEncryptionAlgorithm()->getString()
446 429
         );
447 430
 
448 431
         if (is_null($content_encryption_algorithm))
449
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
450
-            (
451
-                sprintf
452
-                (
432
+            throw new JWEUnsupportedContentEncryptionAlgorithmException(
433
+                sprintf(
453 434
                     'enc %s',
454 435
                     $this->header->getEncryptionAlgorithm()->getString()
455 436
                 )
@@ -470,8 +451,7 @@  discard block
 block discarded – undo
470 451
          * rejecting the input without emitting any decrypted output if the
471 452
          * JWE Authentication Tag is incorrect.
472 453
          */
473
-        $plain_text = $content_encryption_algorithm->decrypt
474
-        (
454
+        $plain_text = $content_encryption_algorithm->decrypt(
475 455
             $this->cipher_text,
476 456
             $this->cek->getEncoded(),
477 457
             $this->iv,
@@ -479,12 +459,12 @@  discard block
 block discarded – undo
479 459
             $this->tag
480 460
         );
481 461
 
482
-        $zip     = $this->header->getCompressionAlgorithm();
462
+        $zip = $this->header->getCompressionAlgorithm();
483 463
         /**
484 464
          * If a "zip" parameter was included, uncompress the decrypted
485 465
          * plaintext using the specified compression algorithm.
486 466
          */
487
-        if(!is_null($zip))
467
+        if (!is_null($zip))
488 468
         {
489 469
             $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue());
490 470
             $plain_text = $compression__algorithm->uncompress($plain_text);
Please login to merge, or discard this patch.