66use DomainException ;
77use Exception ;
88use InvalidArgumentException ;
9+ use OpenSSLAsymmetricKey ;
910use UnexpectedValueException ;
1011use DateTime ;
1112
@@ -59,7 +60,7 @@ class JWT
5960 * Decodes a JWT string into a PHP object.
6061 *
6162 * @param string $jwt The JWT
62- * @param Key|array<Key> $keyOrKeyArray The Key or array of Key objects.
63+ * @param Key|array<Key>|mixed $keyOrKeyArray The Key or array of Key objects.
6364 * If the algorithm used is asymmetric, this is the public key
6465 * Each Key object contains an algorithm and matching key.
6566 * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
@@ -385,14 +386,20 @@ public static function urlsafeB64Encode($input)
385386 /**
386387 * Determine if an algorithm has been provided for each Key
387388 *
388- * @param string |array $keyOrKeyArray
389+ * @param Key |array<Key>|mixed $keyOrKeyArray
389390 * @param string|null $kid
390391 *
391- * @return an array containing the keyMaterial and algorithm
392+ * @throws UnexpectedValueException
393+ *
394+ * @return array containing the keyMaterial and algorithm
392395 */
393396 private static function getKeyMaterialAndAlgorithm ($ keyOrKeyArray , $ kid = null )
394397 {
395- if (is_string ($ keyOrKeyArray )) {
398+ if (
399+ is_string ($ keyOrKeyArray )
400+ || is_resource ($ keyOrKeyArray )
401+ || $ keyOrKeyArray instanceof OpenSSLAsymmetricKey
402+ ) {
396403 return array ($ keyOrKeyArray , null );
397404 }
398405
@@ -418,7 +425,7 @@ private static function getKeyMaterialAndAlgorithm($keyOrKeyArray, $kid = null)
418425 }
419426
420427 throw new UnexpectedValueException (
421- '$keyOrKeyArray must be a string key, an array of string keys, '
428+ '$keyOrKeyArray must be a string|resource key, an array of string|resource keys, '
422429 . 'an instance of Firebase\JWT\Key key or an array of Firebase\JWT\Key keys '
423430 );
424431 }
0 commit comments