Debian Codegraph @

lib/3rdParty/composer/firebase/php-jwt/src/Key.php

raw symbols SCIP
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 /**
13 * @param string|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
14 * @param string $algorithm
15 */
16 public function __construct(
17 #[\SensitiveParameter] private $keyMaterial,
18 private string $algorithm
19 ) {
20 if (
21 !\is_string($keyMaterial)
22 && !$keyMaterial instanceof OpenSSLAsymmetricKey
23 && !$keyMaterial instanceof OpenSSLCertificate
24 ) {
25 throw new TypeError('Key material must be a string, OpenSSLCertificate, or OpenSSLAsymmetricKey');
26 }
27
28 if (empty($keyMaterial)) {
29 throw new InvalidArgumentException('Key material must not be empty');
30 }
31
32 if (empty($algorithm)) {
33 throw new InvalidArgumentException('Algorithm must not be empty');
34 }
35 }
36
37 /**
38 * Return the algorithm valid for this key
39 *
40 * @return string
41 */
42 public function getAlgorithm(): string
43 {
44 return $this->algorithm;
45 }
46
47 /**
48 * @return string|OpenSSLAsymmetricKey|OpenSSLCertificate
49 */
50 public function getKeyMaterial()
51 {
52 return $this->keyMaterial;
53 }
54 }