Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwarajanand authored Dec 29, 2023
1 parent 510c9a6 commit 877e0f2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use SimpleJWT\JWT as SimpleJWT;
use SimpleJWT\Keys\KeyFactory;
use SimpleJWT\Keys\KeySet;
use TypeError;
use UnexpectedValueException;

/**
Expand Down Expand Up @@ -399,6 +400,10 @@ private function checkAndInitializePhpsec()
}
}

/**
* @return string
* @throws TypeError If the key cannot be initialized to a string.
*/
private function loadPhpsecPublicKey(string $modulus, string $exponent): string
{
if (class_exists(RSA::class) && class_exists(BigInteger2::class)) {
Expand All @@ -411,7 +416,11 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent): string
$exponent
]), 256),
]);
return $key->getPublicKey();
$formattedPublicKey = $key->getPublicKey();
if (is_string($formattedPublicKey)) {
return $formattedPublicKey;
}
throw new TypeError('Failed to initialize the key');
}
$key = PublicKeyLoader::load([
'n' => new BigInteger3($this->callJwtStatic('urlsafeB64Decode', [
Expand All @@ -421,7 +430,12 @@ private function loadPhpsecPublicKey(string $modulus, string $exponent): string
$exponent
]), 256),
]);
return $key->toString('PKCS8');
// Ensure the key is correctly initialized
$formattedPublicKey = $key->toString('PKCS8');
if (is_string($formattedPublicKey)) {
return $formattedPublicKey;
}
throw new TypeError('Failed to initialize the key');
}

/**
Expand Down

0 comments on commit 877e0f2

Please sign in to comment.