Skip to content

Commit

Permalink
Lazy vytvoření klíčů
Browse files Browse the repository at this point in the history
 - je to celkem náročná operace
 - nevytváříme tak zbytečně klíče, když je AsymetricJwtTokenizer uvedený jako závislost, ale při aktuálním běhu aplikace ho nevyužijeme
  • Loading branch information
tomasfoltyn committed Jan 19, 2024
1 parent 5ddf88d commit 123f7dc
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/Tokenizer/AsymetricJwtTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,64 @@ final class AsymetricJwtTokenizer implements Tokenizer
*/
private $privateKey;

private string $privateKeyFile;

/**
* @var mixed
*/
private $publicKey;

private string $publicKeyFile;


public function __construct(
string $privateKey,
string $publicKey
)
{
$this->privateKey = \openssl_pkey_get_private('file://' . $privateKey);
$this->publicKey = \openssl_pkey_get_public('file://' . $publicKey);
$this->privateKeyFile = $privateKey;
$this->publicKeyFile= $publicKey;
}


public function create(\Pd\PublicAccess\PublicAccess $object): string
{
return \Firebase\JWT\JWT::encode($object->jsonSerialize(), $this->privateKey, self::ALGORITHM);
return \Firebase\JWT\JWT::encode($object->jsonSerialize(), $this->privateKey(), self::ALGORITHM);

Check failure on line 38 in src/Tokenizer/AsymetricJwtTokenizer.php

View workflow job for this annotation

GitHub Actions / Checks (7.4)

Parameter #2 $key of static method Firebase\JWT\JWT::encode() expects OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string, resource|false given.
}


public function decode(string $token): \stdClass
{
/** @var \stdClass $decode */
$decode = \Firebase\JWT\JWT::decode($token, new \Firebase\JWT\Key($this->publicKey, self::ALGORITHM));
$decode = \Firebase\JWT\JWT::decode($token, new \Firebase\JWT\Key($this->publicKey(), self::ALGORITHM));

Check failure on line 45 in src/Tokenizer/AsymetricJwtTokenizer.php

View workflow job for this annotation

GitHub Actions / Checks (7.4)

Parameter #1 $keyMaterial of class Firebase\JWT\Key constructor expects OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string, resource|false given.

return $decode;
}


/**
* @return false|resource
*/
private function privateKey()
{
if ( ! isset($this->privateKey)) {
$this->privateKey = \openssl_pkey_get_private('file://' . $this->privateKeyFile);
}

return $this->privateKey;
}


/**
* @return false|resource
*/
private function publicKey()
{
if ( ! isset($this->publicKey)) {
$this->publicKey = \openssl_pkey_get_public('file://' . $this->publicKeyFile);
}

return $this->publicKey;
}

}

0 comments on commit 123f7dc

Please sign in to comment.