Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Apply fixes from StyleCI #207

Merged
merged 1 commit into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apply fixes from StyleCI
[ci skip] [skip ci]
  • Loading branch information
Spomky authored and StyleCIBot committed Aug 18, 2017
commit 1ffbe892deab16f5ac92de1db0b96316c4837cad
7 changes: 4 additions & 3 deletions src/Component/Checker/ClaimCheckerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Jose\Component\Core\JWTInterface;

/**
* Class ClaimCheckerManager
* Class ClaimCheckerManager.
*/
final class ClaimCheckerManager
{
Expand Down Expand Up @@ -44,8 +44,9 @@ public function check(JWTInterface $jwt)
}

foreach ($this->checkers as $claim => $checker) {
if (array_key_exists($claim, $claims))
$checker->checkClaim($claims[$claim]);
if (array_key_exists($claim, $claims)) {
$checker->checkClaim($claims[$claim]);
}
}
}
}
1 change: 1 addition & 0 deletions src/Component/Checker/ExpirationTimeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ExpirationTimeChecker implements ClaimCheckerInterface, HeaderChecke

/**
* ExpirationTimeChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
7 changes: 4 additions & 3 deletions src/Component/Checker/HeaderCheckerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Jose\Component\Signature\JWS;

/**
* Class HeaderCheckerManager
* Class HeaderCheckerManager.
*/
final class HeaderCheckerManager
{
Expand All @@ -37,16 +37,18 @@ public function add(HeaderCheckerInterface $checker)

/**
* @param JWTInterface $jwt
* @param int $component
* @param int $component
*/
public function check(JWTInterface $jwt, int $component)
{
switch (true) {
case $jwt instanceof JWS:
$this->checkJWS($jwt, $component);

break;
case $jwt instanceof JWE:
$this->checkJWE($jwt, $component);

break;
default:
throw new \InvalidArgumentException('Unsupported argument');
Expand Down Expand Up @@ -129,7 +131,6 @@ private function checkHeaders(array $protected, array $headers)
}

if (array_key_exists('crit', $protected)) {

if (!is_array($protected['crit'])) {
throw new \InvalidArgumentException('The header "crit" mus be a list of header parameters.');
}
Expand Down
1 change: 1 addition & 0 deletions src/Component/Checker/IssuedAtChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class IssuedAtChecker implements ClaimCheckerInterface, HeaderCheckerInter

/**
* IssuedAtChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
1 change: 1 addition & 0 deletions src/Component/Checker/NotBeforeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class NotBeforeChecker implements ClaimCheckerInterface, HeaderCheckerInte

/**
* NotBeforeChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Checker/Tests/JWSCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Base64Url\Base64Url;
use Jose\Component\Checker\AudienceChecker;
use Jose\Component\Checker\ClaimCheckerManager;
use Jose\Component\Checker\CriticalHeaderChecker;
use Jose\Component\Checker\ExpirationTimeChecker;
use Jose\Component\Checker\HeaderCheckerManager;
use Jose\Component\Checker\IssuedAtChecker;
Expand Down Expand Up @@ -190,7 +189,7 @@ public function testJWSBadTokenID()
public function testJWSSuccessfullyCheckedWithCriticalHeaders()
{
$payload = ['jti' => 'JTI1', 'exp' => time() + 3600, 'iat' => time() - 100, 'nbf' => time() - 100, 'iss' => 'ISS1', 'sub' => 'SUB1', 'aud' => ['My Service']];
$headers = ['alg' => 'none','jti' => 'JTI1', 'exp' => time() + 3600, 'crit' => ['exp', 'jti']];
$headers = ['alg' => 'none', 'jti' => 'JTI1', 'exp' => time() + 3600, 'crit' => ['exp', 'jti']];
$jws = JWS::create(json_encode($payload))
->addSignature('', Base64Url::encode(json_encode($headers)));

Expand Down
1 change: 1 addition & 0 deletions src/Component/Checker/Tests/Stub/IssuerChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class IssuerChecker implements ClaimCheckerInterface, HeaderCheckerInterfa

/**
* IssuerChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
1 change: 1 addition & 0 deletions src/Component/Checker/Tests/Stub/JtiChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class JtiChecker implements ClaimCheckerInterface, HeaderCheckerInterface

/**
* JtiChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
1 change: 1 addition & 0 deletions src/Component/Checker/Tests/Stub/SubjectChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class SubjectChecker implements ClaimCheckerInterface, HeaderCheckerInterf

/**
* SubjectChecker constructor.
*
* @param bool $protectedHeader
*/
public function __construct(bool $protectedHeader = false)
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Core/JWK.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public function toPEM(): string
case 'RSA':
$rsa = RSAKey::createFromJWK($this);
$this->pem = $rsa->toPEM();

break;
case 'EC':
$rsa = ECKey::createFromJWK($this);
$this->pem = $rsa->toPEM();

break;
default:
throw new \LogicException('Only RSA and EC key can be converted into PEM.');
Expand Down
1 change: 1 addition & 0 deletions src/Component/Core/JWKSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static function createFromKeyData(array $data): JWKSet
$jwk = JWK::create($key);
if ($jwk->has('kid')) {
$keys[$jwk->get('kid')] = $jwk;

continue;
}
$keys[] = $jwk;
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Core/Util/RSAKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ private function findPrimeFactors(BigInteger $d, BigInteger $e, BigInteger $n):

if ($x->equals($one)) {
$found = true;

break;
}

Expand All @@ -316,6 +317,7 @@ private function findPrimeFactors(BigInteger $d, BigInteger $e, BigInteger $n):
$x = $y->modPow($two, $n);
if ($x->equals($one)) {
$found = true;

break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Component/Encryption/Algorithm/KeyEncryption/ECDHES.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public function getAgreementKey(int $encryption_key_length, string $algorithm, J
case 'P-384':
case 'P-521':
$private_key = JWKFactory::createECKey($public_key->get('crv'));

break;
case 'X25519':
$private_key = JWKFactory::createOKPKey('X25519');

break;
default:
throw new \InvalidArgumentException(sprintf('The curve "%s" is not supported', $public_key->get('crv')));
Expand Down Expand Up @@ -162,11 +164,13 @@ private function checkKey(JWK $key, $is_private)
if (!$key->has('y')) {
throw new \InvalidArgumentException('The key parameter "y" is missing.');
}

break;
case 'X25519':
if ('OKP' !== $key->get('kty')) {
throw new \InvalidArgumentException('Wrong key type.');
}

break;
default:
throw new \InvalidArgumentException(sprintf('The curve "%s" is not supported', $key->get('crv')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected function checkHeaderAdditionalParameters(array $header)
}
if (empty($header[$k])) {
var_dump();

throw new \InvalidArgumentException(sprintf('The header parameter "%s" is not valid.', $k));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Encryption/JWE.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public function getSharedProtectedHeader(string $key)
if ($this->hasSharedProtectedHeader($key)) {
return $this->sharedProtectedHeaders[$key];
}

throw new \InvalidArgumentException(sprintf('The shared protected header "%s" does not exist.', $key));
}

Expand Down Expand Up @@ -259,6 +260,7 @@ public function getSharedHeader(string $key)
if ($this->hasSharedHeader($key)) {
return $this->sharedHeaders[$key];
}

throw new \InvalidArgumentException(sprintf('The shared header "%s" does not exist.', $key));
}

Expand Down
1 change: 1 addition & 0 deletions src/Component/Encryption/JWEBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ private function getEncryptedKey(array $completeHeaders, string $cek, KeyEncrypt
} elseif ($keyEncryptionAlgorithm instanceof DirectEncryptionInterface) {
return null;
}

throw new \InvalidArgumentException('Unsupported key encryption algorithm.');
}

Expand Down
1 change: 1 addition & 0 deletions src/Component/Encryption/JWELoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private static function convert(string $input): array
} elseif (is_string($input)) {
return self::fromCompactSerializationToSerialization($input);
}

throw new \InvalidArgumentException('Unsupported input');
}

Expand Down
1 change: 1 addition & 0 deletions src/Component/Encryption/Recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function getHeader(string $key)
if ($this->hasHeader($key)) {
return $this->headers[$key];
}

throw new \InvalidArgumentException(sprintf('The header "%s" does not exist.', $key));
}

Expand Down
10 changes: 6 additions & 4 deletions src/Component/KeyManagement/JWKFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class JWKFactory
{
/**
* @param int $size The key size in bits
* @param array $values Values to configure the key.
* @param array $values values to configure the key
*
* @return JWK
*/
Expand Down Expand Up @@ -53,7 +53,7 @@ public static function createRSAKey(int $size, array $values = []): JWK

/**
* @param string $curve The curve
* @param array $values Values to configure the key.
* @param array $values values to configure the key
*
* @return JWK
*/
Expand All @@ -80,7 +80,7 @@ public static function createECKey(string $curve, array $values = []): JWK

/**
* @param int $size The key size in bits
* @param array $values Values to configure the key.
* @param array $values values to configure the key
*
* @return JWK
*/
Expand All @@ -102,7 +102,7 @@ public static function createOctKey(int $size, array $values = []): JWK

/**
* @param string $curve The curve
* @param array $values Values to configure the key.
* @param array $values values to configure the key
*
* @return JWK
*/
Expand All @@ -112,11 +112,13 @@ public static function createOKPKey(string $curve, array $values = []): JWK
case 'X25519':
$d = sodium_randombytes_buf(\Sodium\CRYPTO_BOX_SEEDBYTES);
$x = sodium_crypto_scalarmult_base($d);

break;
case 'Ed25519':
$d = sodium_randombytes_buf(\Sodium\CRYPTO_SIGN_SEEDBYTES);
$keyPair = sodium_crypto_sign_seed_keypair($d);
$x = sodium_crypto_sign_publickey($keyPair);

break;
default:
throw new \InvalidArgumentException(sprintf('Unsupported "%s" curve', $curve));
Expand Down
2 changes: 1 addition & 1 deletion src/Component/KeyManagement/KeyConverter/ECKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use FG\ASN1\Universal\OctetString;
use FG\ASN1\Universal\Sequence;
use Jose\Component\Core\JWK;
use function MongoDB\BSON\toJSON;

final class ECKey
{
Expand Down Expand Up @@ -111,6 +110,7 @@ private function loadPEM(string $data)

return;
}

throw new \Exception('Unable to load the key.');
}

Expand Down
4 changes: 4 additions & 0 deletions src/Component/KeyManagement/KeyConverter/KeyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static function loadKeyFromX509Resource($res): array

return $values;
}

throw new \InvalidArgumentException('Unable to load the certificate');
}

Expand Down Expand Up @@ -214,6 +215,7 @@ public static function loadFromX5C(array $x5c): array
if (false === $x509) {
$last_issuer = null;
$last_subject = null;

break;
}
$parsed = openssl_x509_parse($x509);
Expand All @@ -222,6 +224,7 @@ public static function loadFromX5C(array $x5c): array
if (false === $parsed) {
$last_issuer = null;
$last_subject = null;

break;
}
if (null === $last_subject) {
Expand All @@ -235,6 +238,7 @@ public static function loadFromX5C(array $x5c): array
} else {
$last_issuer = null;
$last_subject = null;

break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Component/KeyManagement/KeyConverter/RSAKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ private function findPrimeFactors(BigInteger $d, BigInteger $e, BigInteger $n):

if ($x->equals($one)) {
$found = true;

break;
}

Expand All @@ -473,6 +474,7 @@ private function findPrimeFactors(BigInteger $d, BigInteger $e, BigInteger $n):
$x = $y->modPow($two, $n);
if ($x->equals($one)) {
$found = true;

break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Component/Signature/JWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function getSignature(int $id): Signature
if (isset($this->signatures[$id])) {
return $this->signatures[$id];
}

throw new \InvalidArgumentException('The signature does not exist.');
}

Expand Down
1 change: 1 addition & 0 deletions src/Component/Signature/JWSConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function convert(string $input): array
} elseif (is_string($input)) {
return self::fromCompactSerializationToSerialization($input);
}

throw new \InvalidArgumentException('Unsupported input');
}

Expand Down
2 changes: 2 additions & 0 deletions src/Component/Signature/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function getProtectedHeader(string $key)
if ($this->hasProtectedHeader($key)) {
return $this->getProtectedHeaders()[$key];
}

throw new \InvalidArgumentException(sprintf('The protected header "%s" does not exist', $key));
}

Expand All @@ -138,6 +139,7 @@ public function getHeader(string $key)
if ($this->hasHeader($key)) {
return $this->headers[$key];
}

throw new \InvalidArgumentException(sprintf('The header "%s" does not exist', $key));
}

Expand Down
Loading