@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @param Key $management_key |
| 35 | - * @param $key_management_mode |
|
| 35 | + * @param string $key_management_mode |
|
| 36 | 36 | * @param ContentEncryptionAlgorithm $enc |
| 37 | 37 | * @return Key |
| 38 | 38 | * @throws \Exception |
@@ -1,16 +1,16 @@ |
||
| 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 jwe\impl; |
| 16 | 16 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * The CEK MUST have a length equal to that required for the |
| 58 | 58 | * content encryption algorithm. |
| 59 | 59 | */ |
| 60 | - $rnd = $generator->invoke($enc->getMinKeyLen()/8); |
|
| 60 | + $rnd = $generator->invoke($enc->getMinKeyLen() / 8); |
|
| 61 | 61 | $cek = new _ContentEncryptionKey($enc->getName(), 'RAW', $rnd); |
| 62 | 62 | } |
| 63 | 63 | break; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param EncryptionAlgorithm $alg |
| 86 | 86 | * @return Key |
| 87 | 87 | */ |
| 88 | - static public function fromRaw($value, EncryptionAlgorithm $alg){ |
|
| 88 | + static public function fromRaw($value, EncryptionAlgorithm $alg) { |
|
| 89 | 89 | return new _ContentEncryptionKey($alg->getName(), 'RAW', $value); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | \ No newline at end of file |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | final class IVFactory { |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * @param $size |
|
| 26 | + * @param integer $size |
|
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | static public function build($size){ |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * @param $size |
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | - static public function build($size){ |
|
| 29 | + static public function build($size) { |
|
| 30 | 30 | |
| 31 | 31 | $generator = Utils_Registry::getInstance()->get(Utils_Registry::RandomNumberGeneratorService); |
| 32 | 32 | return $generator->invoke($size / 8); |
@@ -16,7 +16,6 @@ |
||
| 16 | 16 | |
| 17 | 17 | use jwa\cryptographic_algorithms\ContentEncryptionAlgorithms_Registry; |
| 18 | 18 | use jwa\cryptographic_algorithms\EncryptionAlgorithm; |
| 19 | -use jwa\cryptographic_algorithms\exceptions\InvalidAuthenticationTagException; |
|
| 20 | 19 | use jwa\cryptographic_algorithms\exceptions\InvalidKeyTypeAlgorithmException; |
| 21 | 20 | use jwa\cryptographic_algorithms\key_management\modes\DirectEncryption; |
| 22 | 21 | use jwa\cryptographic_algorithms\key_management\modes\DirectKeyAgreement; |
@@ -1,16 +1,16 @@ |
||
| 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 jwe\impl; |
| 16 | 16 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | protected function __construct(IJWEJOSEHeader $header, IJWSPayloadSpec $payload = null) |
| 99 | 99 | { |
| 100 | 100 | $this->header = $header; |
| 101 | - if(!is_null($payload)) |
|
| 101 | + if (!is_null($payload)) |
|
| 102 | 102 | $this->setPayload($payload); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * the result be the JWE Encrypted Key. |
| 185 | 185 | */ |
| 186 | 186 | $key_management_mode = $this->getKeyManagementMode($alg); |
| 187 | - switch($key_management_mode){ |
|
| 187 | + switch ($key_management_mode) { |
|
| 188 | 188 | case KeyManagementModeValues::KeyEncryption: |
| 189 | 189 | case KeyManagementModeValues::KeyWrapping: |
| 190 | 190 | case KeyManagementModeValues::KeyAgreementWithKeyWrapping: |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | private function getKeyManagementMode(EncryptionAlgorithm $alg) |
| 214 | 214 | { |
| 215 | - if($alg instanceof KeyEncryption) |
|
| 215 | + if ($alg instanceof KeyEncryption) |
|
| 216 | 216 | return KeyManagementModeValues::KeyEncryption; |
| 217 | - if($alg instanceof KeyWrapping) |
|
| 217 | + if ($alg instanceof KeyWrapping) |
|
| 218 | 218 | return KeyManagementModeValues::KeyWrapping; |
| 219 | - if($alg instanceof DirectKeyAgreement) |
|
| 219 | + if ($alg instanceof DirectKeyAgreement) |
|
| 220 | 220 | return KeyManagementModeValues::DirectKeyAgreement; |
| 221 | - if($alg instanceof KeyAgreementWithKeyWrapping) |
|
| 221 | + if ($alg instanceof KeyAgreementWithKeyWrapping) |
|
| 222 | 222 | return KeyManagementModeValues::KeyAgreementWithKeyWrapping; |
| 223 | - if($alg instanceof DirectEncryption) |
|
| 223 | + if ($alg instanceof DirectEncryption) |
|
| 224 | 224 | return KeyManagementModeValues::DirectEncryption; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -239,11 +239,9 @@ discard block |
||
| 239 | 239 | if (is_null($this->jwk)) |
| 240 | 240 | throw new JWEInvalidRecipientKeyException; |
| 241 | 241 | |
| 242 | - if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) |
|
| 243 | - throw new InvalidJWKAlgorithm |
|
| 244 | - ( |
|
| 245 | - sprintf |
|
| 246 | - ( |
|
| 242 | + if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString()) |
|
| 243 | + throw new InvalidJWKAlgorithm( |
|
| 244 | + sprintf( |
|
| 247 | 245 | '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', |
| 248 | 246 | $this->jwk->getAlgorithm()->getValue(), |
| 249 | 247 | $this->header->getAlgorithm()->getString() |
@@ -257,27 +255,22 @@ discard block |
||
| 257 | 255 | if (is_null($key_management_algorithm)) |
| 258 | 256 | throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString())); |
| 259 | 257 | |
| 260 | - if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm()) |
|
| 261 | - throw new InvalidKeyTypeAlgorithmException |
|
| 262 | - ( |
|
| 263 | - sprintf |
|
| 264 | - ( |
|
| 258 | + if ($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm()) |
|
| 259 | + throw new InvalidKeyTypeAlgorithmException( |
|
| 260 | + sprintf( |
|
| 265 | 261 | 'key should be for alg %s, %s instead.', |
| 266 | 262 | $key_management_algorithm->getKeyType(), |
| 267 | 263 | $recipient_public_key->getAlgorithm() |
| 268 | 264 | ) |
| 269 | 265 | ); |
| 270 | 266 | |
| 271 | - $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
| 272 | - ( |
|
| 267 | + $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get( |
|
| 273 | 268 | $this->header->getEncryptionAlgorithm()->getString() |
| 274 | 269 | ); |
| 275 | 270 | |
| 276 | 271 | if (is_null($content_encryption_algorithm)) |
| 277 | - throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 278 | - ( |
|
| 279 | - sprintf |
|
| 280 | - ( |
|
| 272 | + throw new JWEUnsupportedContentEncryptionAlgorithmException( |
|
| 273 | + sprintf( |
|
| 281 | 274 | 'enc %s', |
| 282 | 275 | $this->header->getEncryptionAlgorithm()->getString() |
| 283 | 276 | ) |
@@ -285,8 +278,7 @@ discard block |
||
| 285 | 278 | |
| 286 | 279 | $key_management_mode = $this->getKeyManagementMode($key_management_algorithm); |
| 287 | 280 | |
| 288 | - $this->cek = ContentEncryptionKeyFactory::build |
|
| 289 | - ( |
|
| 281 | + $this->cek = ContentEncryptionKeyFactory::build( |
|
| 290 | 282 | $recipient_public_key, |
| 291 | 283 | $key_management_mode, |
| 292 | 284 | $content_encryption_algorithm |
@@ -300,7 +292,7 @@ discard block |
||
| 300 | 292 | * algorithm); otherwise, let the JWE Initialization Vector be the |
| 301 | 293 | * empty octet sequence. |
| 302 | 294 | */ |
| 303 | - $this->iv = ''; |
|
| 295 | + $this->iv = ''; |
|
| 304 | 296 | |
| 305 | 297 | if (!is_null($iv_size = $content_encryption_algorithm->getIVSize())) |
| 306 | 298 | { |
@@ -317,10 +309,10 @@ discard block |
||
| 317 | 309 | * sequence representing the compressed plaintext; otherwise, let M |
| 318 | 310 | * be the octet sequence representing the plaintext. |
| 319 | 311 | */ |
| 320 | - if(!is_null($zip)) |
|
| 312 | + if (!is_null($zip)) |
|
| 321 | 313 | { |
| 322 | 314 | $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue()); |
| 323 | - $payload = $compression__algorithm->compress($payload); |
|
| 315 | + $payload = $compression__algorithm->compress($payload); |
|
| 324 | 316 | } |
| 325 | 317 | |
| 326 | 318 | /** |
@@ -330,8 +322,7 @@ discard block |
||
| 330 | 322 | * JWE Authentication Tag (which is the Authentication Tag output |
| 331 | 323 | * from the encryption operation). |
| 332 | 324 | */ |
| 333 | - list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt |
|
| 334 | - ( |
|
| 325 | + list($this->cipher_text, $this->tag) = $content_encryption_algorithm->encrypt( |
|
| 335 | 326 | $payload, |
| 336 | 327 | $this->cek->getEncoded(), |
| 337 | 328 | $this->iv, |
@@ -349,23 +340,21 @@ discard block |
||
| 349 | 340 | * @throws InvalidKeyTypeAlgorithmException |
| 350 | 341 | * @throws \Exception |
| 351 | 342 | */ |
| 352 | - private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg){ |
|
| 343 | + private function decryptJWEEncryptedKey(EncryptionAlgorithm $alg) { |
|
| 353 | 344 | |
| 354 | 345 | $key_management_mode = $this->getKeyManagementMode($alg); |
| 355 | 346 | $recipient_private_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption); |
| 356 | 347 | |
| 357 | - if($alg->getKeyType() !== $recipient_private_key->getAlgorithm()) |
|
| 358 | - throw new InvalidKeyTypeAlgorithmException |
|
| 359 | - ( |
|
| 360 | - sprintf |
|
| 361 | - ( |
|
| 348 | + if ($alg->getKeyType() !== $recipient_private_key->getAlgorithm()) |
|
| 349 | + throw new InvalidKeyTypeAlgorithmException( |
|
| 350 | + sprintf( |
|
| 362 | 351 | 'key should be for alg %s, %s instead.', |
| 363 | 352 | $alg->getKeyType(), |
| 364 | 353 | $recipient_private_key->getAlgorithm() |
| 365 | 354 | ) |
| 366 | 355 | ); |
| 367 | 356 | |
| 368 | - switch($key_management_mode){ |
|
| 357 | + switch ($key_management_mode) { |
|
| 369 | 358 | /** |
| 370 | 359 | * When Key Wrapping, Key Encryption, or Key Agreement with Key |
| 371 | 360 | * Wrapping are employed, decrypt the JWE Encrypted Key to produce |
@@ -387,12 +376,12 @@ discard block |
||
| 387 | 376 | * symmetric key. |
| 388 | 377 | */ |
| 389 | 378 | case KeyManagementModeValues::DirectEncryption: |
| 390 | - if(!empty($this->enc_cek)) |
|
| 379 | + if (!empty($this->enc_cek)) |
|
| 391 | 380 | throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
| 392 | 381 | return $recipient_private_key; |
| 393 | 382 | break; |
| 394 | 383 | case KeyManagementModeValues::DirectKeyAgreement: |
| 395 | - if(!empty($this->enc_cek)) |
|
| 384 | + if (!empty($this->enc_cek)) |
|
| 396 | 385 | throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
| 397 | 386 | throw new \Exception('unsupported Key Management Mode!'); |
| 398 | 387 | break; |
@@ -417,42 +406,34 @@ discard block |
||
| 417 | 406 | |
| 418 | 407 | if (!$this->should_decrypt) return $this; |
| 419 | 408 | |
| 420 | - if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) |
|
| 421 | - throw new InvalidJWKAlgorithm |
|
| 422 | - ( |
|
| 423 | - sprintf |
|
| 424 | - ( |
|
| 409 | + if ($this->jwk->getAlgorithm()->getValue() !== $this->header->getAlgorithm()->getString()) |
|
| 410 | + throw new InvalidJWKAlgorithm( |
|
| 411 | + sprintf( |
|
| 425 | 412 | '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', |
| 426 | 413 | $this->jwk->getAlgorithm()->getValue(), |
| 427 | 414 | $this->header->getAlgorithm()->getString() |
| 428 | 415 | ) |
| 429 | 416 | ); |
| 430 | 417 | |
| 431 | - $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
| 432 | - ( |
|
| 418 | + $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get( |
|
| 433 | 419 | $this->header->getAlgorithm()->getString() |
| 434 | 420 | ); |
| 435 | 421 | |
| 436 | 422 | if (is_null($key_management_algorithm)) |
| 437 | - throw new JWEUnsupportedKeyManagementAlgorithmException |
|
| 438 | - ( |
|
| 439 | - sprintf |
|
| 440 | - ( |
|
| 423 | + throw new JWEUnsupportedKeyManagementAlgorithmException( |
|
| 424 | + sprintf( |
|
| 441 | 425 | 'alg %s', |
| 442 | 426 | $this->header->getAlgorithm()->getString() |
| 443 | 427 | ) |
| 444 | 428 | ); |
| 445 | 429 | |
| 446 | - $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
| 447 | - ( |
|
| 430 | + $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get( |
|
| 448 | 431 | $this->header->getEncryptionAlgorithm()->getString() |
| 449 | 432 | ); |
| 450 | 433 | |
| 451 | 434 | if (is_null($content_encryption_algorithm)) |
| 452 | - throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 453 | - ( |
|
| 454 | - sprintf |
|
| 455 | - ( |
|
| 435 | + throw new JWEUnsupportedContentEncryptionAlgorithmException( |
|
| 436 | + sprintf( |
|
| 456 | 437 | 'enc %s', |
| 457 | 438 | $this->header->getEncryptionAlgorithm()->getString() |
| 458 | 439 | ) |
@@ -473,8 +454,7 @@ discard block |
||
| 473 | 454 | * rejecting the input without emitting any decrypted output if the |
| 474 | 455 | * JWE Authentication Tag is incorrect. |
| 475 | 456 | */ |
| 476 | - $plain_text = $content_encryption_algorithm->decrypt |
|
| 477 | - ( |
|
| 457 | + $plain_text = $content_encryption_algorithm->decrypt( |
|
| 478 | 458 | $this->cipher_text, |
| 479 | 459 | $this->cek->getEncoded(), |
| 480 | 460 | $this->iv, |
@@ -482,12 +462,12 @@ discard block |
||
| 482 | 462 | $this->tag |
| 483 | 463 | ); |
| 484 | 464 | |
| 485 | - $zip = $this->header->getCompressionAlgorithm(); |
|
| 465 | + $zip = $this->header->getCompressionAlgorithm(); |
|
| 486 | 466 | /** |
| 487 | 467 | * If a "zip" parameter was included, uncompress the decrypted |
| 488 | 468 | * plaintext using the specified compression algorithm. |
| 489 | 469 | */ |
| 490 | - if(!is_null($zip)) |
|
| 470 | + if (!is_null($zip)) |
|
| 491 | 471 | { |
| 492 | 472 | $compression__algorithm = CompressionAlgorithms_Registry::getInstance()->get($zip->getValue()); |
| 493 | 473 | $plain_text = $compression__algorithm->uncompress($plain_text); |
@@ -98,8 +98,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 457 | 477 | $this->header->getEncryptionAlgorithm()->getString() |
| 458 | 478 | ) |
| 459 | 479 | ); |
| 480 | + } |
|
| 460 | 481 | |
| 461 | 482 | $this->cek = $this->decryptJWEEncryptedKey($key_management_algorithm); |
| 462 | 483 | |
@@ -144,7 +144,7 @@ |
||
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param PrivateKey $private_key |
| 147 | - * @return IAsymmetricJWK|null |
|
| 147 | + * @return RSAJWK |
|
| 148 | 148 | * @throws InvalidJWKType |
| 149 | 149 | */ |
| 150 | 150 | static public function fromPrivateKey(PrivateKey $private_key) |
@@ -1,16 +1,16 @@ |
||
| 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\impl; |
| 16 | 16 | |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | static public function fromKeys(KeyPair $keys) |
| 114 | 114 | { |
| 115 | - if(!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 115 | + if (!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 116 | 116 | throw new \RuntimeException('Private key of invalid type!'); |
| 117 | 117 | |
| 118 | - if(!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 118 | + if (!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 119 | 119 | throw new \RuntimeException('Public key of invalid type!'); |
| 120 | 120 | |
| 121 | 121 | $jwk = new RSAJWK(); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function getKey($key_op = JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC) |
| 167 | 167 | { |
| 168 | - switch($key_op){ |
|
| 168 | + switch ($key_op) { |
|
| 169 | 169 | case JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC: |
| 170 | 170 | case JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption: { |
| 171 | 171 | return $this->getPrivateKey(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | break; |
| 179 | 179 | default:{ |
| 180 | - throw new InvalidJWKUseException(sprintf('key_op %s', $key_op)); |
|
| 180 | + throw new InvalidJWKUseException(sprintf('key_op %s', $key_op)); |
|
| 181 | 181 | } |
| 182 | 182 | break; |
| 183 | 183 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | public function toArray() |
| 191 | 191 | { |
| 192 | 192 | $res = parent::toArray(); |
| 193 | - if($this->visibility === JSONWebKeyVisibility::PublicOnly){ |
|
| 193 | + if ($this->visibility === JSONWebKeyVisibility::PublicOnly) { |
|
| 194 | 194 | //remove private attributes |
| 195 | 195 | unset($res[RSAKeysParameters::PrivateExponent]); |
| 196 | 196 | unset($res[RSAKeysParameters::FirstPrimeFactor]); |
@@ -53,11 +53,14 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | parent::__construct($headers); |
| 55 | 55 | |
| 56 | - if (count($headers) === 0) return; |
|
| 56 | + if (count($headers) === 0) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | foreach (RSAKeysParameters::$public_key_params as $p) { |
| 59 | - if (!array_key_exists($p, $headers)) |
|
| 60 | - throw new RSAJWKMissingPublicKeyParamException(); |
|
| 61 | + if (!array_key_exists($p, $headers)) { |
|
| 62 | + throw new RSAJWKMissingPublicKeyParamException(); |
|
| 63 | + } |
|
| 61 | 64 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 62 | 65 | } |
| 63 | 66 | |
@@ -74,8 +77,9 @@ discard block |
||
| 74 | 77 | //its has one private param, must have all ... |
| 75 | 78 | if (in_array(RSAKeysParameters::FirstPrimeFactor, $headers)) { |
| 76 | 79 | foreach (RSAKeysParameters::$producers_private_key_params as $p) { |
| 77 | - if (!array_key_exists($p, $headers)) |
|
| 78 | - throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 80 | + if (!array_key_exists($p, $headers)) { |
|
| 81 | + throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 82 | + } |
|
| 79 | 83 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 80 | 84 | } |
| 81 | 85 | $this->private_key = RSAFacade::getInstance()->buildPrivateKey( |
@@ -112,11 +116,13 @@ discard block |
||
| 112 | 116 | */ |
| 113 | 117 | static public function fromKeys(KeyPair $keys) |
| 114 | 118 | { |
| 115 | - if(!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 116 | - throw new \RuntimeException('Private key of invalid type!'); |
|
| 119 | + if(!($keys->getPrivate() instanceof RSAPrivateKey)) { |
|
| 120 | + throw new \RuntimeException('Private key of invalid type!'); |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | - if(!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 119 | - throw new \RuntimeException('Public key of invalid type!'); |
|
| 123 | + if(!($keys->getPublic() instanceof RSAPublicKey)) { |
|
| 124 | + throw new \RuntimeException('Public key of invalid type!'); |
|
| 125 | + } |
|
| 120 | 126 | |
| 121 | 127 | $jwk = new RSAJWK(); |
| 122 | 128 | $jwk->public_key = $keys->getPublic(); |
@@ -134,7 +140,9 @@ discard block |
||
| 134 | 140 | */ |
| 135 | 141 | static public function fromPublicKey(PublicKey $public_key) |
| 136 | 142 | { |
| 137 | - if (!($public_key instanceof RSAPublicKey)) throw new InvalidJWKType(); |
|
| 143 | + if (!($public_key instanceof RSAPublicKey)) { |
|
| 144 | + throw new InvalidJWKType(); |
|
| 145 | + } |
|
| 138 | 146 | $jwk = new RSAJWK(); |
| 139 | 147 | $jwk->public_key = $public_key; |
| 140 | 148 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($public_key->getPublicExponent()); |
@@ -149,7 +157,9 @@ discard block |
||
| 149 | 157 | */ |
| 150 | 158 | static public function fromPrivateKey(PrivateKey $private_key) |
| 151 | 159 | { |
| 152 | - if (!($private_key instanceof RSAPrivateKey)) throw new InvalidJWKType(); |
|
| 160 | + if (!($private_key instanceof RSAPrivateKey)) { |
|
| 161 | + throw new InvalidJWKType(); |
|
| 162 | + } |
|
| 153 | 163 | $jwk = new RSAJWK(); |
| 154 | 164 | $jwk->private_key = $private_key; |
| 155 | 165 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($private_key->getPublicExponent()); |
@@ -39,7 +39,6 @@ |
||
| 39 | 39 | use jwt\utils\JOSEHeaderSerializer; |
| 40 | 40 | use jwt\utils\JWTClaimSetSerializer; |
| 41 | 41 | use jwt\utils\JWTRawSerializer; |
| 42 | -use utils\json_types\JsonArray; |
|
| 43 | 42 | use utils\json_types\JsonValue; |
| 44 | 43 | use utils\json_types\StringOrURI; |
| 45 | 44 | |
@@ -1,16 +1,16 @@ discard block |
||
| 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 jws\impl; |
| 16 | 16 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * @param IJOSEHeader $header |
|
| 309 | - * @param IJWSPayloadSpec $payload |
|
| 310 | - * @param string $signature |
|
| 311 | - * @return IJWS |
|
| 312 | - */ |
|
| 308 | + * @param IJOSEHeader $header |
|
| 309 | + * @param IJWSPayloadSpec $payload |
|
| 310 | + * @param string $signature |
|
| 311 | + * @return IJWS |
|
| 312 | + */ |
|
| 313 | 313 | static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null , $signature = '') |
| 314 | 314 | { |
| 315 | 315 | return new JWS($header, $payload, $signature ); |
@@ -72,14 +72,14 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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,11 +168,11 @@ discard block |
||
| 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 | - if($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) |
|
| 175 | + if ($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) |
|
| 179 | 176 | { |
| 180 | 177 | $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet()); |
| 181 | 178 | } |
@@ -233,27 +230,23 @@ discard block |
||
| 233 | 230 | */ |
| 234 | 231 | public function verify($original_alg) |
| 235 | 232 | { |
| 236 | - if(is_null($this->jwk)) |
|
| 233 | + if (is_null($this->jwk)) |
|
| 237 | 234 | throw new JWSInvalidJWKException; |
| 238 | 235 | |
| 239 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 240 | - throw new JWSInvalidJWKException |
|
| 241 | - ( |
|
| 242 | - sprintf |
|
| 243 | - ( |
|
| 236 | + if ($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 237 | + throw new JWSInvalidJWKException( |
|
| 238 | + sprintf( |
|
| 244 | 239 | 'use %s not supported ', |
| 245 | 240 | $this->jwk->getKeyUse()->getString() |
| 246 | 241 | ) |
| 247 | 242 | ); |
| 248 | 243 | |
| 249 | - if(is_null($this->jwk->getAlgorithm())) |
|
| 244 | + if (is_null($this->jwk->getAlgorithm())) |
|
| 250 | 245 | throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
| 251 | 246 | |
| 252 | - if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
| 253 | - throw new JWSInvalidJWKException |
|
| 254 | - ( |
|
| 255 | - sprintf |
|
| 256 | - ( |
|
| 247 | + if (!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
| 248 | + throw new JWSInvalidJWKException( |
|
| 249 | + sprintf( |
|
| 257 | 250 | 'original kid %s - current kid %s', |
| 258 | 251 | $this->header->getKeyID()->getValue(), |
| 259 | 252 | $this->jwk->getId()->getValue() |
@@ -262,34 +255,30 @@ discard block |
||
| 262 | 255 | |
| 263 | 256 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg); |
| 264 | 257 | |
| 265 | - if(is_null($alg)) |
|
| 258 | + if (is_null($alg)) |
|
| 266 | 259 | throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
| 267 | 260 | |
| 268 | 261 | $former_alg = $this->header->getAlgorithm()->getString(); |
| 269 | 262 | |
| 270 | - if($former_alg != $original_alg) |
|
| 271 | - throw new JWSNotSupportedAlgorithm |
|
| 272 | - ( |
|
| 273 | - sprintf |
|
| 274 | - ( |
|
| 263 | + if ($former_alg != $original_alg) |
|
| 264 | + throw new JWSNotSupportedAlgorithm( |
|
| 265 | + sprintf( |
|
| 275 | 266 | 'former alg %s - original alg %s', |
| 276 | 267 | $former_alg, |
| 277 | 268 | $original_alg |
| 278 | 269 | ) |
| 279 | 270 | ); |
| 280 | 271 | |
| 281 | - if($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
| 282 | - throw new InvalidJWKAlgorithm |
|
| 283 | - ( |
|
| 284 | - sprintf |
|
| 285 | - ( |
|
| 272 | + if ($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
| 273 | + throw new InvalidJWKAlgorithm( |
|
| 274 | + sprintf( |
|
| 286 | 275 | 'mismatch between algorithm intended for use with the key %s and the cryptographic algorithm used to secure the JWS %s', |
| 287 | 276 | $this->jwk->getAlgorithm()->getValue(), |
| 288 | 277 | $original_alg |
| 289 | 278 | ) |
| 290 | 279 | ); |
| 291 | 280 | |
| 292 | - $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
|
| 281 | + $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header).IBasicJWT::SegmentSeparator.$this->getEncodedPayload(); |
|
| 293 | 282 | |
| 294 | 283 | // use public key / secret |
| 295 | 284 | $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::VerifyDigitalSignatureOrMAC); |
@@ -310,9 +299,9 @@ discard block |
||
| 310 | 299 | * @param string $signature |
| 311 | 300 | * @return IJWS |
| 312 | 301 | */ |
| 313 | - static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null , $signature = '') |
|
| 302 | + static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null, $signature = '') |
|
| 314 | 303 | { |
| 315 | - return new JWS($header, $payload, $signature ); |
|
| 304 | + return new JWS($header, $payload, $signature); |
|
| 316 | 305 | } |
| 317 | 306 | |
| 318 | 307 | /** |
@@ -320,10 +309,9 @@ discard block |
||
| 320 | 309 | */ |
| 321 | 310 | public function take() |
| 322 | 311 | { |
| 323 | - $payload = $this->payload->isClaimSet() ? $this->claim_set : $this->payload->getRaw(); |
|
| 312 | + $payload = $this->payload->isClaimSet() ? $this->claim_set : $this->payload->getRaw(); |
|
| 324 | 313 | |
| 325 | - return array |
|
| 326 | - ( |
|
| 314 | + return array( |
|
| 327 | 315 | $this->header, |
| 328 | 316 | $payload, |
| 329 | 317 | $this->signature |
@@ -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 | |
@@ -1,16 +1,16 @@ |
||
| 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 jwa\cryptographic_algorithms; |
| 16 | 16 | |
@@ -1,16 +1,16 @@ |
||
| 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 jwa\cryptographic_algorithms; |
| 16 | 16 | |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::Dir] = new DirAlgorithm; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - private function __clone(){} |
|
| 46 | + private function __clone() {} |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @return KeyManagementAlgorithms_Registry |
| 50 | 50 | */ |
| 51 | 51 | public static function getInstance() |
| 52 | 52 | { |
| 53 | - if(!is_object(self::$instance)) |
|
| 53 | + if (!is_object(self::$instance)) |
|
| 54 | 54 | { |
| 55 | 55 | self::$instance = new KeyManagementAlgorithms_Registry(); |
| 56 | 56 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function get($alg) |
| 74 | 74 | { |
| 75 | - if(!$this->isSupported($alg)) return null; |
|
| 75 | + if (!$this->isSupported($alg)) return null; |
|
| 76 | 76 | return $this->algorithms[$alg]; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -72,7 +72,9 @@ |
||
| 72 | 72 | */ |
| 73 | 73 | public function get($alg) |
| 74 | 74 | { |
| 75 | - if(!$this->isSupported($alg)) return null; |
|
| 75 | + if(!$this->isSupported($alg)) { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 76 | 78 | return $this->algorithms[$alg]; |
| 77 | 79 | } |
| 78 | 80 | } |
| 79 | 81 | \ No newline at end of file |
@@ -1,16 +1,16 @@ |
||
| 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 jwa\cryptographic_algorithms; |
| 16 | 16 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | private $algorithms = array(); |
| 42 | 42 | |
| 43 | - private function __construct(){ |
|
| 43 | + private function __construct() { |
|
| 44 | 44 | |
| 45 | 45 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::HS256] = new HS256_Algorithm; |
| 46 | 46 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::HS384] = new HS384_Algorithm; |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - private function __clone(){} |
|
| 59 | + private function __clone() {} |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @return DigitalSignatures_MACs_Registry |
| 63 | 63 | */ |
| 64 | - public static function getInstance(){ |
|
| 65 | - if(!is_object(self::$instance)){ |
|
| 64 | + public static function getInstance() { |
|
| 65 | + if (!is_object(self::$instance)) { |
|
| 66 | 66 | self::$instance = new DigitalSignatures_MACs_Registry(); |
| 67 | 67 | } |
| 68 | 68 | return self::$instance; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $alg |
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | - public function isSupported($alg){ |
|
| 75 | + public function isSupported($alg) { |
|
| 76 | 76 | return array_key_exists($alg, $this->algorithms); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * @param $alg |
| 81 | 81 | * @return null|DigitalSignatureAlgorithm|MAC_Algorithm |
| 82 | 82 | */ |
| 83 | - public function get($alg){ |
|
| 84 | - if(!$this->isSupported($alg)) return null; |
|
| 83 | + public function get($alg) { |
|
| 84 | + if (!$this->isSupported($alg)) return null; |
|
| 85 | 85 | return $this->algorithms[$alg]; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | \ No newline at end of file |
@@ -81,7 +81,9 @@ |
||
| 81 | 81 | * @return null|DigitalSignatureAlgorithm|MAC_Algorithm |
| 82 | 82 | */ |
| 83 | 83 | public function get($alg){ |
| 84 | - if(!$this->isSupported($alg)) return null; |
|
| 84 | + if(!$this->isSupported($alg)) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 85 | 87 | return $this->algorithms[$alg]; |
| 86 | 88 | } |
| 87 | 89 | } |
| 88 | 90 | \ No newline at end of file |
@@ -1,16 +1,16 @@ |
||
| 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 jwa\cryptographic_algorithms; |
| 16 | 16 | |