Skip to content

Commit 1494082

Browse files
chore: misc cleanup (#439)
1 parent 607dcd4 commit 1494082

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/JWK.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,9 @@ private static function createPemFromModulusAndExponent(
231231
$rsaOID . $rsaPublicKey
232232
);
233233

234-
$rsaPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
234+
return "-----BEGIN PUBLIC KEY-----\r\n" .
235235
\chunk_split(\base64_encode($rsaPublicKey), 64) .
236236
'-----END PUBLIC KEY-----';
237-
238-
return $rsaPublicKey;
239237
}
240238

241239
/**

src/JWT.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function decode(
9898
throw new InvalidArgumentException('Key may not be empty');
9999
}
100100
$tks = \explode('.', $jwt);
101-
if (\count($tks) != 3) {
101+
if (\count($tks) !== 3) {
102102
throw new UnexpectedValueException('Wrong number of segments');
103103
}
104104
list($headb64, $bodyb64, $cryptob64) = $tks;
@@ -136,7 +136,7 @@ public static function decode(
136136
// OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
137137
$sig = self::signatureToDER($sig);
138138
}
139-
if (!self::verify("$headb64.$bodyb64", $sig, $key->getKeyMaterial(), $header->alg)) {
139+
if (!self::verify("${headb64}.${bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
140140
throw new SignatureInvalidException('Signature verification failed');
141141
}
142142

@@ -293,7 +293,8 @@ private static function verify(
293293
$success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line
294294
if ($success === 1) {
295295
return true;
296-
} elseif ($success === 0) {
296+
}
297+
if ($success === 0) {
297298
return false;
298299
}
299300
// returns 1 on success, 0 on failure, -1 on error.
@@ -610,7 +611,7 @@ private static function readDER(string $der, int $offset = 0): array
610611
}
611612

612613
// Value
613-
if ($type == self::ASN1_BIT_STRING) {
614+
if ($type === self::ASN1_BIT_STRING) {
614615
$pos++; // Skip the first contents octet (padding indicator)
615616
$data = \substr($der, $pos, $len - 1);
616617
$pos += $len - 1;

tests/CachedKeySetTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function testCacheItemWithExpiresAfter()
210210
public function testJwtVerify()
211211
{
212212
$privKey1 = file_get_contents(__DIR__ . '/data/rsa1-private.pem');
213-
$payload = array('sub' => 'foo', 'exp' => strtotime('+10 seconds'));
213+
$payload = ['sub' => 'foo', 'exp' => strtotime('+10 seconds')];
214214
$msg = JWT::encode($payload, $privKey1, 'RS256', 'jwk1');
215215

216216
$cacheItem = $this->prophesize(CacheItemInterface::class);

0 commit comments

Comments
 (0)