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