PHP Classes

File: src/Types/Pid.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PASERK PHP   src/Types/Pid.php   Download  
File: src/Types/Pid.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PASERK PHP
Extend PASETO to wrap and serialize keys
Author: By
Last change:
Date: 1 year ago
Size: 1,146 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Paserk\Types;

use
FG\ASN1\Exception\ParserException;
use
ParagonIE\Paserk\{
   
IdCommonTrait,
   
IdInterface,
   
PaserkException
};
use
ParagonIE\Paseto\Exception\InvalidVersionException;
use
ParagonIE\Paseto\Exception\PasetoException;
use
ParagonIE\Paseto\Keys\AsymmetricPublicKey;
use
SodiumException;

/**
 * Class Pid
 * @package ParagonIE\Paserk\Types
 */
class Pid implements IdInterface
{
    use
IdCommonTrait;

   
/**
     * @param AsymmetricPublicKey $pk
     * @return string
     *
     * @throws PaserkException
     * @throws SodiumException
     */
   
public static function encodePublic(AsymmetricPublicKey $pk): string
   
{
        try {
           
$version = $pk->getProtocol();
            return
self::encode($version, (new PublicType($version))->encode($pk));
        } catch (
InvalidVersionException|ParserException|PasetoException|PaserkException $ex) {
            throw new
PaserkException("Invalid public key", 0, $ex);
        }
    }

   
/**
     * @return string
     */
   
public static function getTypeLabel(): string
   
{
        return
'pid';
    }
}