Skip to content

Commit

Permalink
Add toPasetoKey methods to PASERK keys
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 30, 2022
1 parent 4fba245 commit 33a2269
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Operations/Key/SealingPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
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
* @package ParagonIE\Paserk\Operations\Key
*/
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
);
}
}
17 changes: 17 additions & 0 deletions src/Operations/Key/SealingSecretKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare(strict_types=1);
namespace ParagonIE\Paserk\Operations\Key;

use ParagonIE\Paserk\PaserkException;
use ParagonIE\EasyECC\ECDSA\{
PublicKey,
SecretKey
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 33a2269

Please sign in to comment.