| @@ -3,36 +3,41 @@ | ||
| 3 | 3 | namespace Firebase\JWT; |
| 4 | 4 | |
| 5 | 5 | use InvalidArgumentException; |
| 6 | 6 | use OpenSSLAsymmetricKey; |
| 7 | -use OpenSSLCertificate; | |
| 8 | -use TypeError; | |
| 9 | 7 | |
| 10 | 8 | class Key |
| 11 | 9 | { |
| 10 | + /** @var string $algorithm */ | |
| 11 | + private $algorithm; | |
| 12 | + | |
| 13 | + /** @var string|resource|OpenSSLAsymmetricKey $keyMaterial */ | |
| 14 | + private $keyMaterial; | |
| 15 | + | |
| 12 | 16 | /** |
| 13 | - * @param string|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial | |
| 17 | + * @param string|resource|OpenSSLAsymmetricKey $keyMaterial | |
| 14 | 18 | * @param string $algorithm |
| 15 | 19 | */ |
| 16 | - public function __construct( | |
| 17 | - #[\SensitiveParameter] private $keyMaterial, | |
| 18 | - private string $algorithm | |
| 19 | - ) { | |
| 20 | + public function __construct($keyMaterial, $algorithm) | |
| 21 | + { | |
| 20 | 22 | if ( |
| 21 | - !\is_string($keyMaterial) | |
| 23 | + !is_string($keyMaterial) | |
| 24 | + && !is_resource($keyMaterial) | |
| 22 | 25 | && !$keyMaterial instanceof OpenSSLAsymmetricKey |
| 23 | - && !$keyMaterial instanceof OpenSSLCertificate | |
| 24 | 26 | ) { |
| 25 | - throw new TypeError('Key material must be a string, OpenSSLCertificate, or OpenSSLAsymmetricKey'); | |
| 27 | + throw new InvalidArgumentException('Type error: $keyMaterial must be a string, resource, or OpenSSLAsymmetricKey'); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | if (empty($keyMaterial)) { |
| 29 | - throw new InvalidArgumentException('Key material must not be empty'); | |
| 31 | + throw new InvalidArgumentException('Type error: $keyMaterial must not be empty'); | |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | - if (empty($algorithm)) { | |
| 33 | - throw new InvalidArgumentException('Algorithm must not be empty'); | |
| 34 | + if (!is_string($algorithm)|| empty($keyMaterial)) { | |
| 35 | + throw new InvalidArgumentException('Type error: $algorithm must be a string'); | |
| 34 | 36 | } |
| 37 | + | |
| 38 | + $this->keyMaterial = $keyMaterial; | |
| 39 | + $this->algorithm = $algorithm; | |
| 35 | 40 | } |
| 36 | 41 | |
| 37 | 42 | /** |
| 38 | 43 | * Return the algorithm valid for this key |
| @@ -38,15 +43,15 @@ | ||
| 38 | 43 | * Return the algorithm valid for this key |
| 39 | 44 | * |
| 40 | 45 | * @return string |
| 41 | 46 | */ |
| 42 | - public function getAlgorithm(): string | |
| 47 | + public function getAlgorithm() | |
| 43 | 48 | { |
| 44 | 49 | return $this->algorithm; |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | 52 | /** |
| 48 | - * @return string|OpenSSLAsymmetricKey|OpenSSLCertificate | |
| 53 | + * @return string|resource|OpenSSLAsymmetricKey | |
| 49 | 54 | */ |
| 50 | 55 | public function getKeyMaterial() |
| 51 | 56 | { |
| 52 | 57 | return $this->keyMaterial; |