Skip to content

Commit

Permalink
chore: misc cleanup (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihasanpour committed Jul 15, 2022
1 parent 607dcd4 commit 1494082
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/JWK.php
Expand Up @@ -231,11 +231,9 @@ private static function createPemFromModulusAndExponent(
$rsaOID . $rsaPublicKey
);

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

return $rsaPublicKey;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/JWT.php
Expand Up @@ -98,7 +98,7 @@ public static function decode(
throw new InvalidArgumentException('Key may not be empty');
}
$tks = \explode('.', $jwt);
if (\count($tks) != 3) {
if (\count($tks) !== 3) {
throw new UnexpectedValueException('Wrong number of segments');
}
list($headb64, $bodyb64, $cryptob64) = $tks;
Expand Down Expand Up @@ -136,7 +136,7 @@ public static function decode(
// OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
$sig = self::signatureToDER($sig);
}
if (!self::verify("$headb64.$bodyb64", $sig, $key->getKeyMaterial(), $header->alg)) {
if (!self::verify("${headb64}.${bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
throw new SignatureInvalidException('Signature verification failed');
}

Expand Down Expand Up @@ -293,7 +293,8 @@ private static function verify(
$success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line
if ($success === 1) {
return true;
} elseif ($success === 0) {
}
if ($success === 0) {
return false;
}
// returns 1 on success, 0 on failure, -1 on error.
Expand Down Expand Up @@ -610,7 +611,7 @@ private static function readDER(string $der, int $offset = 0): array
}

// Value
if ($type == self::ASN1_BIT_STRING) {
if ($type === self::ASN1_BIT_STRING) {
$pos++; // Skip the first contents octet (padding indicator)
$data = \substr($der, $pos, $len - 1);
$pos += $len - 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/CachedKeySetTest.php
Expand Up @@ -210,7 +210,7 @@ public function testCacheItemWithExpiresAfter()
public function testJwtVerify()
{
$privKey1 = file_get_contents(__DIR__ . '/data/rsa1-private.pem');
$payload = array('sub' => 'foo', 'exp' => strtotime('+10 seconds'));
$payload = ['sub' => 'foo', 'exp' => strtotime('+10 seconds')];
$msg = JWT::encode($payload, $privKey1, 'RS256', 'jwk1');

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

0 comments on commit 1494082

Please sign in to comment.