PluginProbe
Gianism / trunk
Gianism vtrunk
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / vendor / firebase / php-jwt / src / Key.php

Key.php in Gianism trunk, at vendor/firebase/php-jwt/src/Key.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Firebase\JWT;
4
5 use InvalidArgumentException;
6 use OpenSSLAsymmetricKey;
7 use OpenSSLCertificate;
8 use TypeError;
9
10 class Key
11 {
12 /** @var string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate */
13 private $keyMaterial;
14 /** @var string */
15 private $algorithm;
16
17 /**
18 * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
19 * @param string $algorithm
20 */
21 public function __construct(
22 $keyMaterial,
23 string $algorithm
24 ) {
25 if (
26 !\is_string($keyMaterial)
27 && !$keyMaterial instanceof OpenSSLAsymmetricKey
28 && !$keyMaterial instanceof OpenSSLCertificate
29 && !\is_resource($keyMaterial)
30 ) {
31 throw new TypeError('Key material must be a string, resource, or OpenSSLAsymmetricKey');
32 }
33
34 if (empty($keyMaterial)) {
35 throw new InvalidArgumentException('Key material must not be empty');
36 }
37
38 if (empty($algorithm)) {
39 throw new InvalidArgumentException('Algorithm must not be empty');
40 }
41
42 // TODO: Remove in PHP 8.0 in favor of class constructor property promotion
43 $this->keyMaterial = $keyMaterial;
44 $this->algorithm = $algorithm;
45 }
46
47 /**
48 * Return the algorithm valid for this key
49 *
50 * @return string
51 */
52 public function getAlgorithm(): string
53 {
54 return $this->algorithm;
55 }
56
57 /**
58 * @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate
59 */
60 public function getKeyMaterial()
61 {
62 return $this->keyMaterial;
63 }
64 }
65