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 ( 35fc1b...16bc05 )
by sebastian
03:06
created
src/jwe/impl/specs/JWE_ParamsSpecification.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,13 +63,13 @@
 block discarded – undo
63 63
      * @throws JWEInvalidPayloadException
64 64
      * @throws JWEInvalidRecipientKeyException
65 65
      */
66
-    public function __construct(IJWK $key, StringOrURI $alg, StringOrURI $enc, $payload,  JsonValue $zip = null)
66
+    public function __construct(IJWK $key, StringOrURI $alg, StringOrURI $enc, $payload, JsonValue $zip = null)
67 67
     {
68 68
 
69
-        if(is_null($key))
69
+        if (is_null($key))
70 70
             throw new JWEInvalidRecipientKeyException();
71 71
 
72
-        if(is_null($payload))
72
+        if (is_null($payload))
73 73
             throw new JWEInvalidPayloadException('missing payload');
74 74
 
75 75
         $this->key     = $key;
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,11 +66,13 @@
 block discarded – undo
66 66
     public function __construct(IJWK $key, StringOrURI $alg, StringOrURI $enc, $payload,  JsonValue $zip = null)
67 67
     {
68 68
 
69
-        if(is_null($key))
70
-            throw new JWEInvalidRecipientKeyException();
69
+        if(is_null($key)) {
70
+                    throw new JWEInvalidRecipientKeyException();
71
+        }
71 72
 
72
-        if(is_null($payload))
73
-            throw new JWEInvalidPayloadException('missing payload');
73
+        if(is_null($payload)) {
74
+                    throw new JWEInvalidPayloadException('missing payload');
75
+        }
74 76
 
75 77
         $this->key     = $key;
76 78
         $this->alg     = $alg;
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/jwe/impl/_ContentEncryptionKey.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
      * @param string $format
45 45
      * @param string $value
46 46
      */
47
-    public function __construct($alg, $format, $value){
47
+    public function __construct($alg, $format, $value) {
48 48
         $this->alg    = $alg;
49 49
         $this->format = $format;
50 50
         $this->value  = $value;
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/jwe/impl/JWE.php 3 patches
Braces   +60 added lines, -39 removed lines patch added patch discarded remove patch
@@ -98,8 +98,9 @@  discard block
 block discarded – undo
98 98
     protected function __construct(IJWEJOSEHeader $header, IJWSPayloadSpec $payload = null)
99 99
     {
100 100
         $this->header = $header;
101
-        if(!is_null($payload))
102
-            $this->setPayload($payload);
101
+        if(!is_null($payload)) {
102
+                    $this->setPayload($payload);
103
+        }
103 104
     }
104 105
 
105 106
     /**
@@ -155,8 +156,9 @@  discard block
 block discarded – undo
155 156
             $this->decrypt();
156 157
         }
157 158
 
158
-        if (is_null($this->payload))
159
-            $this->payload = JWSPayloadFactory::build('');
159
+        if (is_null($this->payload)) {
160
+                    $this->payload = JWSPayloadFactory::build('');
161
+        }
160 162
 
161 163
         return $this->payload->getRaw();
162 164
     }
@@ -212,16 +214,21 @@  discard block
 block discarded – undo
212 214
      */
213 215
     private function getKeyManagementMode(EncryptionAlgorithm $alg)
214 216
     {
215
-        if($alg instanceof KeyEncryption)
216
-            return KeyManagementModeValues::KeyEncryption;
217
-        if($alg instanceof KeyWrapping)
218
-            return KeyManagementModeValues::KeyWrapping;
219
-        if($alg instanceof DirectKeyAgreement)
220
-            return KeyManagementModeValues::DirectKeyAgreement;
221
-        if($alg instanceof KeyAgreementWithKeyWrapping)
222
-            return KeyManagementModeValues::KeyAgreementWithKeyWrapping;
223
-        if($alg instanceof DirectEncryption)
224
-            return KeyManagementModeValues::DirectEncryption;
217
+        if($alg instanceof KeyEncryption) {
218
+                    return KeyManagementModeValues::KeyEncryption;
219
+        }
220
+        if($alg instanceof KeyWrapping) {
221
+                    return KeyManagementModeValues::KeyWrapping;
222
+        }
223
+        if($alg instanceof DirectKeyAgreement) {
224
+                    return KeyManagementModeValues::DirectKeyAgreement;
225
+        }
226
+        if($alg instanceof KeyAgreementWithKeyWrapping) {
227
+                    return KeyManagementModeValues::KeyAgreementWithKeyWrapping;
228
+        }
229
+        if($alg instanceof DirectEncryption) {
230
+                    return KeyManagementModeValues::DirectEncryption;
231
+        }
225 232
     }
226 233
 
227 234
     /**
@@ -236,11 +243,12 @@  discard block
 block discarded – undo
236 243
     private function encrypt()
237 244
     {
238 245
 
239
-        if (is_null($this->jwk))
240
-            throw new JWEInvalidRecipientKeyException;
246
+        if (is_null($this->jwk)) {
247
+                    throw new JWEInvalidRecipientKeyException;
248
+        }
241 249
 
242
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
243
-            throw new InvalidJWKAlgorithm
250
+        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) {
251
+                    throw new InvalidJWKAlgorithm
244 252
             (
245 253
                 sprintf
246 254
                 (
@@ -249,16 +257,18 @@  discard block
 block discarded – undo
249 257
                     $this->header->getAlgorithm()->getString()
250 258
                 )
251 259
             );
260
+        }
252 261
 
253 262
         $recipient_public_key     = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::EncryptContent);
254 263
 
255 264
         $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get($this->header->getAlgorithm()->getString());
256 265
 
257
-        if (is_null($key_management_algorithm))
258
-            throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString()));
266
+        if (is_null($key_management_algorithm)) {
267
+                    throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString()));
268
+        }
259 269
 
260
-        if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm())
261
-            throw new InvalidKeyTypeAlgorithmException
270
+        if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm()) {
271
+                    throw new InvalidKeyTypeAlgorithmException
262 272
             (
263 273
                 sprintf
264 274
                 (
@@ -267,14 +277,15 @@  discard block
 block discarded – undo
267 277
                     $recipient_public_key->getAlgorithm()
268 278
                 )
269 279
             );
280
+        }
270 281
 
271 282
         $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
272 283
         (
273 284
             $this->header->getEncryptionAlgorithm()->getString()
274 285
         );
275 286
 
276
-        if (is_null($content_encryption_algorithm))
277
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
287
+        if (is_null($content_encryption_algorithm)) {
288
+                    throw new JWEUnsupportedContentEncryptionAlgorithmException
278 289
             (
279 290
                 sprintf
280 291
                 (
@@ -282,6 +293,7 @@  discard block
 block discarded – undo
282 293
                     $this->header->getEncryptionAlgorithm()->getString()
283 294
                 )
284 295
             );
296
+        }
285 297
 
286 298
         $key_management_mode = $this->getKeyManagementMode($key_management_algorithm);
287 299
 
@@ -354,8 +366,8 @@  discard block
 block discarded – undo
354 366
         $key_management_mode   = $this->getKeyManagementMode($alg);
355 367
         $recipient_private_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption);
356 368
 
357
-        if($alg->getKeyType() !== $recipient_private_key->getAlgorithm())
358
-            throw new InvalidKeyTypeAlgorithmException
369
+        if($alg->getKeyType() !== $recipient_private_key->getAlgorithm()) {
370
+                    throw new InvalidKeyTypeAlgorithmException
359 371
             (
360 372
                 sprintf
361 373
                 (
@@ -364,6 +376,7 @@  discard block
 block discarded – undo
364 376
                     $recipient_private_key->getAlgorithm()
365 377
                 )
366 378
             );
379
+        }
367 380
 
368 381
         switch($key_management_mode){
369 382
             /**
@@ -387,13 +400,15 @@  discard block
 block discarded – undo
387 400
              * symmetric key.
388 401
              */
389 402
             case KeyManagementModeValues::DirectEncryption:
390
-                if(!empty($this->enc_cek))
391
-                    throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
403
+                if(!empty($this->enc_cek)) {
404
+                                    throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
405
+                }
392 406
                 return $recipient_private_key;
393 407
             break;
394 408
             case KeyManagementModeValues::DirectKeyAgreement:
395
-                if(!empty($this->enc_cek))
396
-                    throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
409
+                if(!empty($this->enc_cek)) {
410
+                                    throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
411
+                }
397 412
                 throw new \Exception('unsupported Key Management Mode!');
398 413
             break;
399 414
         }
@@ -412,13 +427,16 @@  discard block
 block discarded – undo
412 427
      */
413 428
     private function decrypt()
414 429
     {
415
-        if (is_null($this->jwk))
416
-            throw new JWEInvalidRecipientKeyException();
430
+        if (is_null($this->jwk)) {
431
+                    throw new JWEInvalidRecipientKeyException();
432
+        }
417 433
 
418
-        if (!$this->should_decrypt) return $this;
434
+        if (!$this->should_decrypt) {
435
+         return $this;
436
+        }
419 437
 
420
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
421
-            throw new InvalidJWKAlgorithm
438
+        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) {
439
+                    throw new InvalidJWKAlgorithm
422 440
             (
423 441
                 sprintf
424 442
                 (
@@ -427,14 +445,15 @@  discard block
 block discarded – undo
427 445
                     $this->header->getAlgorithm()->getString()
428 446
                 )
429 447
             );
448
+        }
430 449
 
431 450
         $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get
432 451
         (
433 452
             $this->header->getAlgorithm()->getString()
434 453
         );
435 454
 
436
-        if (is_null($key_management_algorithm))
437
-            throw new JWEUnsupportedKeyManagementAlgorithmException
455
+        if (is_null($key_management_algorithm)) {
456
+                    throw new JWEUnsupportedKeyManagementAlgorithmException
438 457
             (
439 458
                 sprintf
440 459
                 (
@@ -442,14 +461,15 @@  discard block
 block discarded – undo
442 461
                     $this->header->getAlgorithm()->getString()
443 462
                 )
444 463
             );
464
+        }
445 465
 
446 466
         $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
447 467
         (
448 468
             $this->header->getEncryptionAlgorithm()->getString()
449 469
         );
450 470
 
451
-        if (is_null($content_encryption_algorithm))
452
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
471
+        if (is_null($content_encryption_algorithm)) {
472
+                    throw new JWEUnsupportedContentEncryptionAlgorithmException
453 473
             (
454 474
                 sprintf
455 475
                 (
@@ -457,6 +477,7 @@  discard block
 block discarded – undo
457 477
                     $this->header->getEncryptionAlgorithm()->getString()
458 478
                 )
459 479
             );
480
+        }
460 481
 
461 482
         $this->cek = $this->decryptJWEEncryptedKey($key_management_algorithm);
462 483
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
     }
143 143
 
144 144
     /**
145
-     * @return mixed
145
+     * @return string
146 146
      * @throws JWEInvalidRecipientKeyException
147 147
      * @throws JWEUnsupportedContentEncryptionAlgorithmException
148 148
      * @throws JWEUnsupportedKeyManagementAlgorithmException
Please login to merge, or discard this patch.
Spacing   +42 added lines, -62 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
     /**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
          * the result be the JWE Encrypted Key.
184 184
          */
185 185
          $key_management_mode = $this->getKeyManagementMode($alg);
186
-         switch($key_management_mode){
186
+         switch ($key_management_mode) {
187 187
              case KeyManagementModeValues::KeyEncryption:
188 188
              case KeyManagementModeValues::KeyWrapping:
189 189
              case KeyManagementModeValues::KeyAgreementWithKeyWrapping:
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
      */
212 212
     private function getKeyManagementMode(EncryptionAlgorithm $alg)
213 213
     {
214
-        if($alg instanceof KeyEncryption)
214
+        if ($alg instanceof KeyEncryption)
215 215
             return KeyManagementModeValues::KeyEncryption;
216
-        if($alg instanceof KeyWrapping)
216
+        if ($alg instanceof KeyWrapping)
217 217
             return KeyManagementModeValues::KeyWrapping;
218
-        if($alg instanceof DirectKeyAgreement)
218
+        if ($alg instanceof DirectKeyAgreement)
219 219
             return KeyManagementModeValues::DirectKeyAgreement;
220
-        if($alg instanceof KeyAgreementWithKeyWrapping)
220
+        if ($alg instanceof KeyAgreementWithKeyWrapping)
221 221
             return KeyManagementModeValues::KeyAgreementWithKeyWrapping;
222
-        if($alg instanceof DirectEncryption)
222
+        if ($alg instanceof DirectEncryption)
223 223
             return KeyManagementModeValues::DirectEncryption;
224 224
     }
225 225
 
@@ -238,11 +238,9 @@  discard block
 block discarded – undo
238 238
         if (is_null($this->jwk))
239 239
             throw new JWEInvalidRecipientKeyException;
240 240
 
241
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
242
-            throw new InvalidJWKAlgorithm
243
-            (
244
-                sprintf
245
-                (
241
+        if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString())
242
+            throw new InvalidJWKAlgorithm(
243
+                sprintf(
246 244
                     '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',
247 245
                     $this->jwk->getAlgorithm()->getValue(),
248 246
                     $this->header->getAlgorithm()->getString()
@@ -256,27 +254,22 @@  discard block
 block discarded – undo
256 254
         if (is_null($key_management_algorithm))
257 255
             throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString()));
258 256
 
259
-        if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm())
260
-            throw new InvalidKeyTypeAlgorithmException
261
-            (
262
-                sprintf
263
-                (
257
+        if ($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm())
258
+            throw new InvalidKeyTypeAlgorithmException(
259
+                sprintf(
264 260
                     'key should be for alg %s, %s instead.',
265 261
                     $key_management_algorithm->getKeyType(),
266 262
                     $recipient_public_key->getAlgorithm()
267 263
                 )
268 264
             );
269 265
 
270
-        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
271
-        (
266
+        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get(
272 267
             $this->header->getEncryptionAlgorithm()->getString()
273 268
         );
274 269
 
275 270
         if (is_null($content_encryption_algorithm))
276
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
277
-            (
278
-                sprintf
279
-                (
271
+            throw new JWEUnsupportedContentEncryptionAlgorithmException(
272
+                sprintf(
280 273
                     'enc %s',
281 274
                     $this->header->getEncryptionAlgorithm()->getString()
282 275
                 )
@@ -284,8 +277,7 @@  discard block
 block discarded – undo
284 277
 
285 278
         $key_management_mode = $this->getKeyManagementMode($key_management_algorithm);
286 279
 
287
-        $this->cek     = ContentEncryptionKeyFactory::build
288
-        (
280
+        $this->cek = ContentEncryptionKeyFactory::build(
289 281
             $recipient_public_key,
290 282
             $key_management_mode,
291 283
             $content_encryption_algorithm
@@ -299,7 +291,7 @@  discard block
 block discarded – undo
299 291
          * algorithm); otherwise, let the JWE Initialization Vector be the
300 292
          * empty octet sequence.
301 293
          */
302
-        $this->iv      = '';
294
+        $this->iv = '';
303 295
 
304 296
         if (!is_null($iv_size = $content_encryption_algorithm->getIVSize()))
305 297
         {
@@ -308,7 +300,7 @@  discard block
 block discarded – undo
308 300
         // We encrypt the payload and get the tag
309 301
         $jwt_shared_protected_header = JOSEHeaderSerializer::serialize($this->header);
310 302
 
311
-        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw():'';
303
+        $payload = ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw() : '';
312 304
         $zip     = $this->header->getCompressionAlgorithm();
313 305
         /**
314 306
          * If a "zip" parameter was included, compress the plaintext using
@@ -316,10 +308,10 @@  discard block
 block discarded – undo
316 308
          * sequence representing the compressed plaintext; otherwise, let M
317 309
          * be the octet sequence representing the plaintext.
318 310
          */
319
-        if(!is_null($zip))
311
+        if (!is_null($zip))
320 312
         {
321 313
             $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue());
322
-            $payload  = $compression__algorithm->compress($payload);
314
+            $payload = $compression__algorithm->compress($payload);
323 315
         }
324 316
 
325 317
         /**
@@ -329,8 +321,7 @@  discard block
 block discarded – undo
329 321
          * JWE Authentication Tag (which is the Authentication Tag output
330 322
          * from the encryption operation).
331 323
          */
332
-        list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt
333
-        (
324
+        list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt(
334 325
             $payload,
335 326
             $this->cek->getEncoded(),
336 327
             $this->iv,
@@ -348,23 +339,21 @@  discard block
 block discarded – undo
348 339
      * @throws InvalidKeyTypeAlgorithmException
349 340
      * @throws \Exception
350 341
      */
351
-    private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg){
342
+    private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg) {
352 343
 
353 344
         $key_management_mode   = $this->getKeyManagementMode($alg);
354 345
         $recipient_private_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption);
355 346
 
356
-        if($alg->getKeyType() !== $recipient_private_key->getAlgorithm())
357
-            throw new InvalidKeyTypeAlgorithmException
358
-            (
359
-                sprintf
360
-                (
347
+        if ($alg->getKeyType() !== $recipient_private_key->getAlgorithm())
348
+            throw new InvalidKeyTypeAlgorithmException(
349
+                sprintf(
361 350
                     'key should be for alg %s, %s instead.',
362 351
                     $alg->getKeyType(),
363 352
                     $recipient_private_key->getAlgorithm()
364 353
                 )
365 354
             );
366 355
 
367
-        switch($key_management_mode){
356
+        switch ($key_management_mode) {
368 357
             /**
369 358
              * When Key Wrapping, Key Encryption, or Key Agreement with Key
370 359
              * Wrapping are employed, decrypt the JWE Encrypted Key to produce
@@ -386,12 +375,12 @@  discard block
 block discarded – undo
386 375
              * symmetric key.
387 376
              */
388 377
             case KeyManagementModeValues::DirectEncryption:
389
-                if(!empty($this->enc_cek))
378
+                if (!empty($this->enc_cek))
390 379
                     throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
391 380
                 return $recipient_private_key;
392 381
             break;
393 382
             case KeyManagementModeValues::DirectKeyAgreement:
394
-                if(!empty($this->enc_cek))
383
+                if (!empty($this->enc_cek))
395 384
                     throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.');
396 385
                 throw new \Exception('unsupported Key Management Mode!');
397 386
             break;
@@ -416,42 +405,34 @@  discard block
 block discarded – undo
416 405
 
417 406
         if (!$this->should_decrypt) return $this;
418 407
 
419
-        if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString())
420
-            throw new InvalidJWKAlgorithm
421
-            (
422
-                sprintf
423
-                (
408
+        if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString())
409
+            throw new InvalidJWKAlgorithm(
410
+                sprintf(
424 411
                     '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',
425 412
                     $this->jwk->getAlgorithm()->getValue(),
426 413
                     $this->header->getAlgorithm()->getString()
427 414
                 )
428 415
             );
429 416
 
430
-        $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get
431
-        (
417
+        $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get(
432 418
             $this->header->getAlgorithm()->getString()
433 419
         );
434 420
 
435 421
         if (is_null($key_management_algorithm))
436
-            throw new JWEUnsupportedKeyManagementAlgorithmException
437
-            (
438
-                sprintf
439
-                (
422
+            throw new JWEUnsupportedKeyManagementAlgorithmException(
423
+                sprintf(
440 424
                     'alg %s',
441 425
                     $this->header->getAlgorithm()->getString()
442 426
                 )
443 427
             );
444 428
 
445
-        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get
446
-        (
429
+        $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get(
447 430
             $this->header->getEncryptionAlgorithm()->getString()
448 431
         );
449 432
 
450 433
         if (is_null($content_encryption_algorithm))
451
-            throw new JWEUnsupportedContentEncryptionAlgorithmException
452
-            (
453
-                sprintf
454
-                (
434
+            throw new JWEUnsupportedContentEncryptionAlgorithmException(
435
+                sprintf(
455 436
                     'enc %s',
456 437
                     $this->header->getEncryptionAlgorithm()->getString()
457 438
                 )
@@ -472,8 +453,7 @@  discard block
 block discarded – undo
472 453
          * rejecting the input without emitting any decrypted output if the
473 454
          * JWE Authentication Tag is incorrect.
474 455
          */
475
-        $plain_text = $content_encryption_algorithm->decrypt
476
-        (
456
+        $plain_text = $content_encryption_algorithm->decrypt(
477 457
             $this->cipher_text,
478 458
             $this->cek->getEncoded(),
479 459
             $this->iv,
@@ -481,12 +461,12 @@  discard block
 block discarded – undo
481 461
             $this->tag
482 462
         );
483 463
 
484
-        $zip     = $this->header->getCompressionAlgorithm();
464
+        $zip = $this->header->getCompressionAlgorithm();
485 465
         /**
486 466
          * If a "zip" parameter was included, uncompress the decrypted
487 467
          * plaintext using the specified compression algorithm.
488 468
          */
489
-        if(!is_null($zip))
469
+        if (!is_null($zip))
490 470
         {
491 471
             $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue());
492 472
             $plain_text = $compression__algorithm->uncompress($plain_text);
Please login to merge, or discard this patch.
src/jwe/RegisteredJWEJOSEHeaderNames.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     const CompressionAlgorithm = 'zip';
65 65
 
66 66
 
67
-    public static $registered_basic_headers_set = array (
67
+    public static $registered_basic_headers_set = array(
68 68
         self::Algorithm,
69 69
         self::EncryptionAlgorithm,
70 70
         self::KeyID,
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
         self::ContentType,
74 74
     );
75 75
 
76
-    public static $registered_basic_headers_set_types = array (
77
-        self::Algorithm            => JsonTypes::StringOrURI ,
76
+    public static $registered_basic_headers_set_types = array(
77
+        self::Algorithm            => JsonTypes::StringOrURI,
78 78
         self::Type                 => JsonTypes::StringOrURI,
79 79
         self::ContentType          => JsonTypes::StringOrURI,
80 80
         self::KeyID                => JsonTypes::JsonValue,
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/jwe/KeyManagementModeValues.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@
 block discarded – undo
24 24
 
25 25
     const KeyWrapping = 'wrap';
26 26
 
27
-    const DirectKeyAgreement ='agree';
27
+    const DirectKeyAgreement = 'agree';
28 28
 
29
-    const KeyAgreementWithKeyWrapping ='agree_wrap';
29
+    const KeyAgreementWithKeyWrapping = 'agree_wrap';
30 30
 
31 31
     const DirectEncryption = 'dir';
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/jwe/JWEFactory.php 2 patches
Spacing   +11 added lines, -16 removed lines patch added patch discarded remove patch
@@ -37,41 +37,36 @@  discard block
 block discarded – undo
37 37
     static public function build(IJWE_Specification $spec)
38 38
     {
39 39
 
40
-        if($spec instanceof IJWE_ParamsSpecification)
40
+        if ($spec instanceof IJWE_ParamsSpecification)
41 41
         {
42 42
 
43
-            if($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption)
44
-                throw new InvalidJWKType
45
-                (
46
-                    sprintf
47
-                    (
43
+            if ($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption)
44
+                throw new InvalidJWKType(
45
+                    sprintf(
48 46
                         'use %s not supported (should be "enc")',
49 47
                         $spec->getRecipientKey()->getKeyUse()->getString()
50 48
                     )
51 49
                 );
52 50
 
53
-            if($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString())
54
-                throw new InvalidJWKAlgorithm
55
-                (
56
-                    sprintf
57
-                    (
51
+            if ($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString())
52
+                throw new InvalidJWKAlgorithm(
53
+                    sprintf(
58 54
                         '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',
59 55
                         $spec->getAlg()->getString(),
60 56
                         $spec->getRecipientKey()->getAlgorithm()->getString()
61 57
                     )
62 58
                 );
63 59
 
64
-            $header = new JWEJOSEHeader
65
-            (
60
+            $header = new JWEJOSEHeader(
66 61
                 $spec->getAlg(),
67 62
                 $spec->getEnc(),
68 63
                 $spec->getRecipientKey()->getId()
69 64
             );
70 65
 
71 66
             //set zip alg
72
-            $zip    = $spec->getZip();
67
+            $zip = $spec->getZip();
73 68
 
74
-            if(!is_null($zip))
69
+            if (!is_null($zip))
75 70
                 $header->setCompressionAlgorithm($zip);
76 71
 
77 72
             $jwe = JWE::fromHeaderAndPayload($header, $spec->getPayload());
@@ -81,7 +76,7 @@  discard block
 block discarded – undo
81 76
             return $jwe;
82 77
         }
83 78
 
84
-        if($spec instanceof IJWE_CompactFormatSpecification)
79
+        if ($spec instanceof IJWE_CompactFormatSpecification)
85 80
         {
86 81
             return JWE::fromCompactSerialization($spec->getCompactFormat());
87 82
         }
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
         if($spec instanceof IJWE_ParamsSpecification)
41 41
         {
42 42
 
43
-            if($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption)
44
-                throw new InvalidJWKType
43
+            if($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption) {
44
+                            throw new InvalidJWKType
45 45
                 (
46 46
                     sprintf
47 47
                     (
@@ -49,9 +49,10 @@  discard block
 block discarded – undo
49 49
                         $spec->getRecipientKey()->getKeyUse()->getString()
50 50
                     )
51 51
                 );
52
+            }
52 53
 
53
-            if($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString())
54
-                throw new InvalidJWKAlgorithm
54
+            if($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString()) {
55
+                            throw new InvalidJWKAlgorithm
55 56
                 (
56 57
                     sprintf
57 58
                     (
@@ -60,6 +61,7 @@  discard block
 block discarded – undo
60 61
                         $spec->getRecipientKey()->getAlgorithm()->getString()
61 62
                     )
62 63
                 );
64
+            }
63 65
 
64 66
             $header = new JWEJOSEHeader
65 67
             (
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
             //set zip alg
72 74
             $zip    = $spec->getZip();
73 75
 
74
-            if(!is_null($zip))
75
-                $header->setCompressionAlgorithm($zip);
76
+            if(!is_null($zip)) {
77
+                            $header->setCompressionAlgorithm($zip);
78
+            }
76 79
 
77 80
             $jwe = JWE::fromHeaderAndPayload($header, $spec->getPayload());
78 81
 
Please login to merge, or discard this patch.
src/jwe/compression_algorithms/CompressionAlgorithms_Registry.php 3 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
     private $algorithms = array();
33 33
 
34
-    private function __construct(){
34
+    private function __construct() {
35 35
 
36 36
         $this->algorithms[CompressionAlgorithmsNames::Deflate] = new Deflate;
37 37
         $this->algorithms[CompressionAlgorithmsNames::GZip]    = new GZip;
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 
40 40
     }
41 41
 
42
-    private function __clone(){}
42
+    private function __clone() {}
43 43
 
44 44
     /**
45 45
      * @return CompressionAlgorithms_Registry
46 46
      */
47
-    public static function getInstance(){
48
-        if(!is_object(self::$instance)){
47
+    public static function getInstance() {
48
+        if (!is_object(self::$instance)) {
49 49
             self::$instance = new CompressionAlgorithms_Registry();
50 50
         }
51 51
         return self::$instance;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * @param string $alg
56 56
      * @return bool
57 57
      */
58
-    public function isSupported($alg){
58
+    public function isSupported($alg) {
59 59
         return array_key_exists($alg, $this->algorithms);
60 60
     }
61 61
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
      * @param $alg
64 64
      * @return null|CompressionAlgorithm
65 65
      */
66
-    public function get($alg){
67
-        if(!$this->isSupported($alg)) return null;
66
+    public function get($alg) {
67
+        if (!$this->isSupported($alg)) return null;
68 68
         return $this->algorithms[$alg];
69 69
     }
70 70
 }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@
 block discarded – undo
64 64
      * @return null|CompressionAlgorithm
65 65
      */
66 66
     public function get($alg){
67
-        if(!$this->isSupported($alg)) return null;
67
+        if(!$this->isSupported($alg)) {
68
+         return null;
69
+        }
68 70
         return $this->algorithms[$alg];
69 71
     }
70 72
 }
71 73
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/security/SymmetricSharedKey.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     /**
28 28
      * @param string $secret
29 29
      */
30
-    public function __construct($secret){
30
+    public function __construct($secret) {
31 31
         $this->secret = $secret;
32 32
     }
33 33
 
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.
src/security/rsa/_RSAPrivateKeyPEMFornat.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
      * @param string $password
34 34
      * @throws RSABadPEMFormat
35 35
      */
36
-    public function __construct($pem_format, $password = null){
36
+    public function __construct($pem_format, $password = null) {
37 37
 
38 38
         parent::__construct($pem_format, $password);
39 39
         $this->d = $this->rsa_imp->exponent;
40
-        if($this->d->toString() === $this->e->toString())
40
+        if ($this->d->toString() === $this->e->toString())
41 41
             throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format));
42 42
     }
43 43
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
     public function getEncoded()
58 58
     {
59 59
         $pem = $this->rsa_imp->getPrivateKey(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
60
-        $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/','',$pem);
61
-        $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/','',$pem);
62
-        $pem = str_replace( array("\n","\r","\t"), '', trim($pem));
60
+        $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/', '', $pem);
61
+        $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/', '', $pem);
62
+        $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem));
63 63
         return $pem;
64 64
     }
65 65
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@
 block discarded – undo
37 37
 
38 38
         parent::__construct($pem_format, $password);
39 39
         $this->d = $this->rsa_imp->exponent;
40
-        if($this->d->toString() === $this->e->toString())
41
-            throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format));
40
+        if($this->d->toString() === $this->e->toString()) {
41
+                    throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format));
42
+        }
42 43
     }
43 44
 
44 45
     /**
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Copyright 2015 OpenStack Foundation
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- **/
3
+     * Copyright 2015 OpenStack Foundation
4
+     * Licensed under the Apache License, Version 2.0 (the "License");
5
+     * you may not use this file except in compliance with the License.
6
+     * You may obtain a copy of the License at
7
+     * http://www.apache.org/licenses/LICENSE-2.0
8
+     * Unless required by applicable law or agreed to in writing, software
9
+     * distributed under the License is distributed on an "AS IS" BASIS,
10
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+     * See the License for the specific language governing permissions and
12
+     * limitations under the License.
13
+     **/
14 14
 
15 15
 namespace jwk;
16 16
 
Please login to merge, or discard this patch.