Skip to content

chore: fixes cs and adds cs checking to travis #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 25, 2020
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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/run-tests.sh export-ignore
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: php

branches:
- only: [master]

php:
- 5.6
- 7.0
Expand All @@ -16,8 +19,18 @@ matrix:
dist: trusty
- php: 5.5
dist: trusty
- name: "Check Style"
php: "7.4"
env: RUN_CS_FIXER=true

sudo: false

before_script: composer install
script: vendor/bin/phpunit
script:
- if [ "${RUN_CS_FIXER}" = "true" ]; then
composer require friendsofphp/php-cs-fixer &&
vendor/bin/php-cs-fixer fix --diff --dry-run . &&
vendor/bin/php-cs-fixer fix --rules=native_function_invocation --allow-risky=yes --diff src;
else
vendor/bin/phpunit;
fi
37 changes: 0 additions & 37 deletions run-tests.sh

This file was deleted.

1 change: 0 additions & 1 deletion src/BeforeValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

class BeforeValidException extends \UnexpectedValueException
{

}
1 change: 0 additions & 1 deletion src/ExpiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

class ExpiredException extends \UnexpectedValueException
{

}
34 changes: 17 additions & 17 deletions src/JWK.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function parseKeySet(array $jwks)
}
}

if (0 === count($keys)) {
if (0 === \count($keys)) {
throw new UnexpectedValueException('No supported algorithms found in JWK Set');
}

Expand Down Expand Up @@ -81,18 +81,18 @@ private static function parseKey(array $jwk)

switch ($jwk['kty']) {
case 'RSA':
if (array_key_exists('d', $jwk)) {
if (\array_key_exists('d', $jwk)) {
throw new UnexpectedValueException('RSA private keys are not supported');
}
if (!isset($jwk['n']) || !isset($jwk['e'])) {
throw new UnexpectedValueException('RSA keys must contain values for both "n" and "e"');
}

$pem = self::createPemFromModulusAndExponent($jwk['n'], $jwk['e']);
$publicKey = openssl_pkey_get_public($pem);
$publicKey = \openssl_pkey_get_public($pem);
if (false === $publicKey) {
throw new DomainException(
'OpenSSL error: ' . openssl_error_string()
'OpenSSL error: ' . \openssl_error_string()
);
}
return $publicKey;
Expand All @@ -118,32 +118,32 @@ private static function createPemFromModulusAndExponent($n, $e)
$publicExponent = JWT::urlsafeB64Decode($e);

$components = array(
'modulus' => pack('Ca*a*', 2, self::encodeLength(strlen($modulus)), $modulus),
'publicExponent' => pack('Ca*a*', 2, self::encodeLength(strlen($publicExponent)), $publicExponent)
'modulus' => \pack('Ca*a*', 2, self::encodeLength(\strlen($modulus)), $modulus),
'publicExponent' => \pack('Ca*a*', 2, self::encodeLength(\strlen($publicExponent)), $publicExponent)
);

$rsaPublicKey = pack(
$rsaPublicKey = \pack(
'Ca*a*a*',
48,
self::encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
self::encodeLength(\strlen($components['modulus']) + \strlen($components['publicExponent'])),
$components['modulus'],
$components['publicExponent']
);

// sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
$rsaPublicKey = chr(0) . $rsaPublicKey;
$rsaPublicKey = chr(3) . self::encodeLength(strlen($rsaPublicKey)) . $rsaPublicKey;
$rsaOID = \pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
$rsaPublicKey = \chr(0) . $rsaPublicKey;
$rsaPublicKey = \chr(3) . self::encodeLength(\strlen($rsaPublicKey)) . $rsaPublicKey;

$rsaPublicKey = pack(
$rsaPublicKey = \pack(
'Ca*a*',
48,
self::encodeLength(strlen($rsaOID . $rsaPublicKey)),
self::encodeLength(\strlen($rsaOID . $rsaPublicKey)),
$rsaOID . $rsaPublicKey
);

$rsaPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
chunk_split(base64_encode($rsaPublicKey), 64) .
\chunk_split(\base64_encode($rsaPublicKey), 64) .
'-----END PUBLIC KEY-----';

return $rsaPublicKey;
Expand All @@ -161,11 +161,11 @@ private static function createPemFromModulusAndExponent($n, $e)
private static function encodeLength($length)
{
if ($length <= 0x7F) {
return chr($length);
return \chr($length);
}

$temp = ltrim(pack('N', $length), chr(0));
$temp = \ltrim(\pack('N', $length), \chr(0));

return pack('Ca*', 0x80 | strlen($temp), $temp);
return \pack('Ca*', 0x80 | \strlen($temp), $temp);
}
}
Loading