All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Firebase\JWT;
|
|
|
|
use InvalidArgumentException;
|
|
use OpenSSLAsymmetricKey;
|
|
use OpenSSLCertificate;
|
|
use TypeError;
|
|
|
|
class Key
|
|
{
|
|
/**
|
|
* @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
|
|
* @param string $algorithm
|
|
*/
|
|
public function __construct(
|
|
private $keyMaterial,
|
|
private string $algorithm
|
|
) {
|
|
if (
|
|
!\is_string($keyMaterial)
|
|
&& !$keyMaterial instanceof OpenSSLAsymmetricKey
|
|
&& !$keyMaterial instanceof OpenSSLCertificate
|
|
&& !\is_resource($keyMaterial)
|
|
) {
|
|
throw new TypeError('Key material must be a string, resource, or OpenSSLAsymmetricKey');
|
|
}
|
|
|
|
if (empty($keyMaterial)) {
|
|
throw new InvalidArgumentException('Key material must not be empty');
|
|
}
|
|
|
|
if (empty($algorithm)) {
|
|
throw new InvalidArgumentException('Algorithm must not be empty');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return the algorithm valid for this key
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getAlgorithm(): string
|
|
{
|
|
return $this->algorithm;
|
|
}
|
|
|
|
/**
|
|
* @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate
|
|
*/
|
|
public function getKeyMaterial()
|
|
{
|
|
return $this->keyMaterial;
|
|
}
|
|
}
|