Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use early static binding/typing #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 3 additions & 40 deletions src/Keys/Base/AsymmetricPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,26 @@
/**
* This used to initialize a v1 public key, but it was deprecated then removed.
*
* @param string $keyMaterial
* @return self
*
* @throws InvalidVersionException
*/
public static function v1(string $keyMaterial): self
public static function v1(string $keyMaterial): static
{
throw new InvalidVersionException("Version 1 was removed", ExceptionCode::OBSOLETE_PROTOCOL);
}

/**
* This used to initialize a v2 public key, but it was deprecated then removed.
*
* @param string $keyMaterial
* @return self
*
* @throws InvalidVersionException
*/
public static function v2(string $keyMaterial): self
public static function v2(string $keyMaterial): static
{
throw new InvalidVersionException("Version 2 was removed", ExceptionCode::OBSOLETE_PROTOCOL);
}

/**
* Initialize a v3 public key.
*
* @param string $keyMaterial
* @return V3AsymmetricPublicKey
*
* @throws Exception
*/
public static function v3(string $keyMaterial): V3AsymmetricPublicKey
Expand All @@ -98,9 +89,6 @@
/**
* Initialize a v4 public key.
*
* @param string $keyMaterial
* @return V4AsymmetricPublicKey
*
* @throws Exception
*/
public static function v4(string $keyMaterial): V4AsymmetricPublicKey
Expand All @@ -111,10 +99,6 @@
/**
* Initialize a public key.
*
* @param string $keyMaterial
* @param ?ProtocolInterface $protocol
* @return self
*
* @throws Exception
*/
public static function newVersionKey(
Expand All @@ -134,27 +118,19 @@
/**
* Returns the base64url-encoded public key.
*
* @return string
*
* @throws TypeError
* @throws PasetoException
*/
abstract public function encode(): string;

/**
* Return a PEM-encoded public key
*
* @return string
*/
abstract public function encodePem(): string;

/**
* Initialize a public key from a base64url-encoded string.
*
* @param string $encoded
* @param ProtocolInterface|null $version
* @return self
*
* @throws Exception
* @throws TypeError
*/
Expand All @@ -175,10 +151,6 @@


/**
* @param string $pem
* @param ProtocolInterface|null $protocol
* @return self
*
* @throws Exception
*/
public static function importPem(string $pem, ?ProtocolInterface $protocol = null): self
Expand All @@ -195,44 +167,35 @@
}

/**
* @return string
* @throws ParserException
*/
abstract public function toHexString(): string;

/**
* Get the version of PASETO that this key is intended for.
*
* @return ProtocolInterface
*/
public function getProtocol(): ProtocolInterface
{
return $this->protocol;
}

/**
* @param ProtocolInterface $protocol
* @return bool
*/
public function isForVersion(ProtocolInterface $protocol): bool
{
return $this->protocol instanceof $protocol;
}

/**
* Get the raw key contents.
*
* @return string
*/
public function raw(): string
{
return $this->key;
}

/**
* @return array
* @return array<>
*/
public function __debugInfo()

Check failure on line 198 in src/Keys/Base/AsymmetricPublicKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricPublicKey.php:198:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricPublicKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 198 in src/Keys/Base/AsymmetricPublicKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricPublicKey.php:198:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricPublicKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 198 in src/Keys/Base/AsymmetricPublicKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricPublicKey.php:198:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricPublicKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 198 in src/Keys/Base/AsymmetricPublicKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricPublicKey.php:198:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricPublicKey::__debugInfo (see https://psalm.dev/008)
{
return [];
}
Expand Down
48 changes: 4 additions & 44 deletions src/Keys/Base/AsymmetricSecretKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,25 @@
/**
* This used to initialize a v1 secret key, but it was deprecated then removed.
*
* @param string $keyMaterial
* @return self
*
* @throws InvalidVersionException
*/
public static function v1(string $keyMaterial): self
public static function v1(string $keyMaterial): static
{
throw new InvalidVersionException("Version 1 was removed", ExceptionCode::OBSOLETE_PROTOCOL);
}

/**
* This used to initialize a v2 secret key, but it was deprecated then removed.
*
* @param string $keyMaterial
* @return self
*
* @throws InvalidVersionException
*/
public static function v2(string $keyMaterial): self
public static function v2(string $keyMaterial): static
{throw new InvalidVersionException("Version 2 was removed", ExceptionCode::OBSOLETE_PROTOCOL);
}

/**
* Initialize a v3 secret key.
*
* @param string $keyMaterial
* @return V3AsymmetricSecretKey
*
* @throws Exception
* @throws TypeError
*/
Expand All @@ -139,9 +130,6 @@
/**
* Initialize a v4 secret key.
*
* @param string $keyMaterial
* @return V4AsymmetricSecretKey
*
* @throws Exception
* @throws TypeError
*/
Expand All @@ -153,9 +141,6 @@
/**
* Generate a secret key.
*
* @param ProtocolInterface|null $protocol
* @return self
*
* @throws Exception
* @throws TypeError
*/
Expand All @@ -172,10 +157,6 @@
/**
* Initialize a public key.
*
* @param string $keyMaterial
* @param ?ProtocolInterface $protocol
* @return self
*
* @throws Exception
*/
public static function newVersionKey(string $keyMaterial, ?ProtocolInterface $protocol = null): self
Expand All @@ -192,27 +173,20 @@
/**
* Return a base64url-encoded representation of this secret key.
*
* @return string
*
* @throws TypeError
*/
abstract public function encode(): string;

/**
* Return a PEM-encoded secret key
*
* @return string
* @throws PasetoException
*/
abstract public function encodePem(): string;

/**
* Initialize a secret key from a base64url-encoded string.
*
* @param string $encoded
* @param ProtocolInterface|null $version
* @return self
*
* @throws Exception
* @throws TypeError
*/
Expand All @@ -226,11 +200,7 @@
}

/**
* @param string $pem
* @param ProtocolInterface|null $protocol
* @return self
*
* @throws Exception
* @throws InvalidVersionException
*/
public static function importPem(string $pem, ?ProtocolInterface $protocol = null): self
{
Expand All @@ -247,18 +217,12 @@

/**
* Get the version of PASETO that this key is intended for.
*
* @return ProtocolInterface
*/
public function getProtocol(): ProtocolInterface
{
return $this->protocol;
}

/**
* @param ProtocolInterface $protocol
* @return bool
*/
public function isForVersion(ProtocolInterface $protocol): bool
{
return $this->protocol instanceof $protocol;
Expand All @@ -267,27 +231,23 @@
/**
* Get the public key that corresponds to this secret key.
*
* @return AsymmetricPublicKey
*
* @throws Exception
* @throws TypeError
*/
abstract public function getPublicKey(): AsymmetricPublicKey;

/**
* Get the raw key contents.
*
* @return string
*/
public function raw(): string
{
return Util::dos2unix($this->key);
}

/**
* @return array
* @return array<>
*/
public function __debugInfo()

Check failure on line 250 in src/Keys/Base/AsymmetricSecretKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricSecretKey.php:250:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricSecretKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 250 in src/Keys/Base/AsymmetricSecretKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricSecretKey.php:250:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricSecretKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 250 in src/Keys/Base/AsymmetricSecretKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricSecretKey.php:250:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricSecretKey::__debugInfo (see https://psalm.dev/008)

Check failure on line 250 in src/Keys/Base/AsymmetricSecretKey.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 Test on ubuntu-latest

InvalidDocblock

src/Keys/Base/AsymmetricSecretKey.php:250:5: InvalidDocblock: Cannot parse generic type in docblock for ParagonIE\Paseto\Keys\Base\AsymmetricSecretKey::__debugInfo (see https://psalm.dev/008)
{
return [];
}
Expand Down
Loading
Loading