Skip to content

Commit

Permalink
feat: add typing, require PHP 8.0 (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Feb 16, 2022
1 parent 8bcbcf8 commit f8550f8
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 277 deletions.
40 changes: 2 additions & 38 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]
php: [ "8.0", "8.1"]
name: PHP ${{matrix.php }} Unit Test
steps:
- uses: actions/checkout@v2
Expand All @@ -24,45 +24,9 @@ jobs:
timeout_minutes: 10
max_attempts: 3
command: composer install
- if: ${{ matrix.php == '5.6' }}
run: composer require --dev --with-dependencies paragonie/sodium_compat
- name: Run Script
run: vendor/bin/phpunit

# use dockerfiles for old versions of php (setup-php times out for those).
test_php55:
name: "PHP 5.5 Unit Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.5-cli
with:
entrypoint: ./.github/actions/entrypoint.sh

test_php54:
name: "PHP 5.4 Unit Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://php:5.4-cli
with:
entrypoint: ./.github/actions/entrypoint.sh

test_php53:
name: "PHP 5.3 Unit Test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
uses: docker://tomsowerby/php-5.3:cli
with:
entrypoint: ./.github/actions/entrypoint.sh

style:
runs-on: ubuntu-latest
name: PHP Style Check
Expand All @@ -71,7 +35,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.0"
php-version: "8.0"
- name: Run Script
run: |
composer require friendsofphp/php-cs-fixer
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"license": "BSD-3-Clause",
"require": {
"php": ">=5.3.0"
"php": "^8.0"
},
"suggest": {
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
Expand All @@ -31,6 +31,6 @@
}
},
"require-dev": {
"phpunit/phpunit": ">=4.8 <=9"
"phpunit/phpunit": "^9.5"
}
}
15 changes: 10 additions & 5 deletions src/JWK.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class JWK
*
* @uses parseKey
*/
public static function parseKeySet(array $jwks)
public static function parseKeySet(array $jwks): array
{
$keys = array();
$keys = [];

if (!isset($jwks['keys'])) {
throw new UnexpectedValueException('"keys" member must exist in the JWK Set');
}

if (empty($jwks['keys'])) {
throw new InvalidArgumentException('JWK Set did not contain any keys');
}
Expand Down Expand Up @@ -71,14 +72,16 @@ public static function parseKeySet(array $jwks)
*
* @uses createPemFromModulusAndExponent
*/
public static function parseKey(array $jwk)
public static function parseKey(array $jwk): ?Key
{
if (empty($jwk)) {
throw new InvalidArgumentException('JWK must not be empty');
}

if (!isset($jwk['kty'])) {
throw new UnexpectedValueException('JWK must contain a "kty" parameter');
}

if (!isset($jwk['alg'])) {
// The "alg" parameter is optional in a KTY, but is required for parsing in
// this library. Add it manually to your JWK array if it doesn't already exist.
Expand Down Expand Up @@ -107,6 +110,8 @@ public static function parseKey(array $jwk)
// Currently only RSA is supported
break;
}

return null;
}

/**
Expand All @@ -124,10 +129,10 @@ private static function createPemFromModulusAndExponent($n, $e)
$modulus = JWT::urlsafeB64Decode($n);
$publicExponent = JWT::urlsafeB64Decode($e);

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

$rsaPublicKey = \pack(
'Ca*a*a*',
Expand Down

0 comments on commit f8550f8

Please sign in to comment.