BeforeValidException.php
3 years ago
ExpiredException.php
3 years ago
JWK.php
3 years ago
JWT.php
3 years ago
Key.php
3 years ago
SignatureInvalidException.php
3 years ago
Key.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP2FA_Vendor\Firebase\JWT; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | use OpenSSLAsymmetricKey; |
| 7 | class Key |
| 8 | { |
| 9 | /** @var string $algorithm */ |
| 10 | private $algorithm; |
| 11 | /** @var string|resource|OpenSSLAsymmetricKey $keyMaterial */ |
| 12 | private $keyMaterial; |
| 13 | /** |
| 14 | * @param string|resource|OpenSSLAsymmetricKey $keyMaterial |
| 15 | * @param string $algorithm |
| 16 | */ |
| 17 | public function __construct($keyMaterial, $algorithm) |
| 18 | { |
| 19 | if (!\is_string($keyMaterial) && !\is_resource($keyMaterial) && !$keyMaterial instanceof OpenSSLAsymmetricKey) { |
| 20 | throw new InvalidArgumentException('Type error: $keyMaterial must be a string, resource, or OpenSSLAsymmetricKey'); |
| 21 | } |
| 22 | if (empty($keyMaterial)) { |
| 23 | throw new InvalidArgumentException('Type error: $keyMaterial must not be empty'); |
| 24 | } |
| 25 | if (!\is_string($algorithm) || empty($keyMaterial)) { |
| 26 | throw new InvalidArgumentException('Type error: $algorithm must be a string'); |
| 27 | } |
| 28 | $this->keyMaterial = $keyMaterial; |
| 29 | $this->algorithm = $algorithm; |
| 30 | } |
| 31 | /** |
| 32 | * Return the algorithm valid for this key |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public function getAlgorithm() |
| 37 | { |
| 38 | return $this->algorithm; |
| 39 | } |
| 40 | /** |
| 41 | * @return string|resource|OpenSSLAsymmetricKey |
| 42 | */ |
| 43 | public function getKeyMaterial() |
| 44 | { |
| 45 | return $this->keyMaterial; |
| 46 | } |
| 47 | } |
| 48 |