| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\GCP\Firebase\JWT; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use OpenSSLAsymmetricKey; |
| 7 |
use OpenSSLCertificate; |
| 8 |
use TypeError; |
| 9 |
class Key |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @param string|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial |
| 13 |
* @param string $algorithm |
| 14 |
*/ |
| 15 |
public function __construct(#[\SensitiveParameter] private $keyMaterial, private string $algorithm) |
| 16 |
{ |
| 17 |
if (!\is_string($keyMaterial) && !$keyMaterial instanceof OpenSSLAsymmetricKey && !$keyMaterial instanceof OpenSSLCertificate) { |
| 18 |
throw new TypeError('Key material must be a string, OpenSSLCertificate, or OpenSSLAsymmetricKey'); |
| 19 |
} |
| 20 |
if (empty($keyMaterial)) { |
| 21 |
throw new InvalidArgumentException('Key material must not be empty'); |
| 22 |
} |
| 23 |
if (empty($algorithm)) { |
| 24 |
throw new InvalidArgumentException('Algorithm must not be empty'); |
| 25 |
} |
| 26 |
} |
| 27 |
/** |
| 28 |
* Return the algorithm valid for this key |
| 29 |
* |
| 30 |
* @return string |
| 31 |
*/ |
| 32 |
public function getAlgorithm() : string |
| 33 |
{ |
| 34 |
return $this->algorithm; |
| 35 |
} |
| 36 |
/** |
| 37 |
* @return string|OpenSSLAsymmetricKey|OpenSSLCertificate |
| 38 |
*/ |
| 39 |
public function getKeyMaterial() |
| 40 |
{ |
| 41 |
return $this->keyMaterial; |
| 42 |
} |
| 43 |
} |
| 44 |
|