Skip to content

Commit 83ac363

Browse files
authored
Merge branch 'main' into add-cached-keyset
2 parents a0f8008 + 52943f5 commit 83ac363

File tree

6 files changed

+145
-88
lines changed

6 files changed

+145
-88
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
php: [ "8.0", "8.1"]
13+
php: [ "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]
1414
name: PHP ${{matrix.php }} Unit Test
1515
steps:
1616
- uses: actions/checkout@v2
@@ -41,3 +41,17 @@ jobs:
4141
composer require friendsofphp/php-cs-fixer
4242
vendor/bin/php-cs-fixer fix --diff --dry-run .
4343
vendor/bin/php-cs-fixer fix --rules=native_function_invocation --allow-risky=yes --diff src
44+
45+
staticanalysis:
46+
runs-on: ubuntu-latest
47+
name: PHPStan Static Analysis
48+
steps:
49+
- uses: actions/checkout@v2
50+
- name: Install PHP
51+
uses: shivammathur/setup-php@v2
52+
with:
53+
php-version: '8.0'
54+
- name: Run Script
55+
run: |
56+
composer global require phpstan/phpstan
57+
~/.composer/vendor/bin/phpstan analyse

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"license": "BSD-3-Clause",
2222
"require": {
23-
"php": "^8.0"
23+
"php": "^7.1||^8.0"
2424
},
2525
"suggest": {
2626
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
@@ -31,7 +31,7 @@
3131
}
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^9.5",
34+
"phpunit/phpunit": "^7.5||9.5"
3535
"psr/cache": "^3.0",
3636
"guzzlehttp/guzzle": "^7.4",
3737
"phpspec/prophecy-phpunit": "^2.0"

phpstan.neon.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src
5+
treatPhpDocTypesAsCertain: false

src/JWK.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JWK
2323
/**
2424
* Parse a set of JWK keys
2525
*
26-
* @param array $jwks The JSON Web Key Set as an associative array
26+
* @param array<mixed> $jwks The JSON Web Key Set as an associative array
2727
*
2828
* @return array<string, Key> An associative array of key IDs (kid) to Key objects
2929
*
@@ -48,7 +48,7 @@ public static function parseKeySet(array $jwks): array
4848
foreach ($jwks['keys'] as $k => $v) {
4949
$kid = isset($v['kid']) ? $v['kid'] : $k;
5050
if ($key = self::parseKey($v)) {
51-
$keys[$kid] = $key;
51+
$keys[(string) $kid] = $key;
5252
}
5353
}
5454

@@ -62,7 +62,7 @@ public static function parseKeySet(array $jwks): array
6262
/**
6363
* Parse a JWK key
6464
*
65-
* @param array $jwk An individual JWK
65+
* @param array<mixed> $jwk An individual JWK
6666
*
6767
* @return Key The key object for the JWK
6868
*
@@ -124,22 +124,22 @@ public static function parseKey(array $jwk): ?Key
124124
*
125125
* @uses encodeLength
126126
*/
127-
private static function createPemFromModulusAndExponent($n, $e)
128-
{
129-
$modulus = JWT::urlsafeB64Decode($n);
130-
$publicExponent = JWT::urlsafeB64Decode($e);
127+
private static function createPemFromModulusAndExponent(
128+
string $n,
129+
string $e
130+
): string {
131+
$mod = JWT::urlsafeB64Decode($n);
132+
$exp = JWT::urlsafeB64Decode($e);
131133

132-
$components = [
133-
'modulus' => \pack('Ca*a*', 2, self::encodeLength(\strlen($modulus)), $modulus),
134-
'publicExponent' => \pack('Ca*a*', 2, self::encodeLength(\strlen($publicExponent)), $publicExponent)
135-
];
134+
$modulus = \pack('Ca*a*', 2, self::encodeLength(\strlen($mod)), $mod);
135+
$publicExponent = \pack('Ca*a*', 2, self::encodeLength(\strlen($exp)), $exp);
136136

137137
$rsaPublicKey = \pack(
138138
'Ca*a*a*',
139139
48,
140-
self::encodeLength(\strlen($components['modulus']) + \strlen($components['publicExponent'])),
141-
$components['modulus'],
142-
$components['publicExponent']
140+
self::encodeLength(\strlen($modulus) + \strlen($publicExponent)),
141+
$modulus,
142+
$publicExponent
143143
);
144144

145145
// sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
@@ -170,7 +170,7 @@ private static function createPemFromModulusAndExponent($n, $e)
170170
* @param int $length
171171
* @return string
172172
*/
173-
private static function encodeLength($length)
173+
private static function encodeLength(int $length): string
174174
{
175175
if ($length <= 0x7F) {
176176
return \chr($length);

0 commit comments

Comments
 (0)