@@ -41,16 +41,18 @@ public function __construct($jwkOrKeyPath)
4141 protected function loadFromPath (string $ path )
4242 {
4343 try {
44- $ this -> key = PublicKeyLoader::load (
44+ $ key = PublicKeyLoader::load (
4545 file_get_contents ($ path )
46- )-> withPadding ( RSA :: SIGNATURE_PKCS1 ) ;
46+ );
4747 } catch (\Exception $ exception ) {
4848 throw new OidcInvalidKeyException ("Failed to load key from file path with error: {$ exception ->getMessage ()}" );
4949 }
5050
51- if (!( $ this -> key instanceof RSA ) ) {
51+ if (!$ key instanceof RSA ) {
5252 throw new OidcInvalidKeyException ('Key loaded from file path is not an RSA key as expected ' );
5353 }
54+
55+ $ this ->key = $ key ->withPadding (RSA ::SIGNATURE_PKCS1 );
5456 }
5557
5658 /**
@@ -81,14 +83,19 @@ protected function loadFromJwkArray(array $jwk)
8183 $ n = strtr ($ jwk ['n ' ] ?? '' , '-_ ' , '+/ ' );
8284
8385 try {
84- /** @var RSA $key */
85- $ this ->key = PublicKeyLoader::load ([
86+ $ key = PublicKeyLoader::load ([
8687 'e ' => new BigInteger (base64_decode ($ jwk ['e ' ]), 256 ),
8788 'n ' => new BigInteger (base64_decode ($ n ), 256 ),
88- ])-> withPadding ( RSA :: SIGNATURE_PKCS1 ) ;
89+ ]);
8990 } catch (\Exception $ exception ) {
9091 throw new OidcInvalidKeyException ("Failed to load key from JWK parameters with error: {$ exception ->getMessage ()}" );
9192 }
93+
94+ if (!$ key instanceof RSA ) {
95+ throw new OidcInvalidKeyException ('Key loaded from file path is not an RSA key as expected ' );
96+ }
97+
98+ $ this ->key = $ key ->withPadding (RSA ::SIGNATURE_PKCS1 );
9299 }
93100
94101 /**
0 commit comments