diff --git a/src/Operations/Key/SealingPublicKey.php b/src/Operations/Key/SealingPublicKey.php index 762ef51..d8fa27f 100644 --- a/src/Operations/Key/SealingPublicKey.php +++ b/src/Operations/Key/SealingPublicKey.php @@ -2,7 +2,9 @@ declare(strict_types=1); namespace ParagonIE\Paserk\Operations\Key; +use ParagonIE\Paserk\PaserkException; use ParagonIE\Paseto\Keys\AsymmetricPublicKey; +use ParagonIE\Paseto\Protocol\Version1; /** * Class SealingPublicKey @@ -10,5 +12,19 @@ */ class SealingPublicKey extends AsymmetricPublicKey { + /** + * @return AsymmetricPublicKey + * @throws PaserkException + */ + public function toPasetoKey(): AsymmetricPublicKey + { + if ($this->protocol instanceof Version1) { + throw new PaserkException("Version 1 keys cannot be converted!"); + } + return new AsymmetricPublicKey( + $this->key, + $this->protocol + ); + } } diff --git a/src/Operations/Key/SealingSecretKey.php b/src/Operations/Key/SealingSecretKey.php index 24bd317..a7f2855 100644 --- a/src/Operations/Key/SealingSecretKey.php +++ b/src/Operations/Key/SealingSecretKey.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace ParagonIE\Paserk\Operations\Key; +use ParagonIE\Paserk\PaserkException; use ParagonIE\EasyECC\ECDSA\{ PublicKey, SecretKey @@ -66,6 +67,22 @@ public static function generate(ProtocolInterface $protocol = null): AsymmetricS ); } + /** + * @return AsymmetricSecretKey + * @throws PaserkException + */ + public function toPasetoKey(): AsymmetricSecretKey + { + if ($this->protocol instanceof Version1) { + throw new PaserkException("Version 1 keys cannot be converted!"); + } + + return new AsymmetricSecretKey( + $this->key, + $this->protocol + ); + } + /** * @return AsymmetricPublicKey *