PHP Classes

File: src/Types/Lid.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PASERK PHP   src/Types/Lid.php   Download  
File: src/Types/Lid.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,034 bytes
 

Contents

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

use
ParagonIE\ConstantTime\Binary;
use
ParagonIE\Paserk\{
   
IdCommonTrait,
   
IdInterface,
   
PaserkException
};
use
ParagonIE\Paseto\Exception\InvalidVersionException;
use
ParagonIE\Paseto\Keys\SymmetricKey;
use
SodiumException;

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

   
/**
     * @param SymmetricKey $key
     * @return string
     *
     * @throws InvalidVersionException
     * @throws PaserkException
     * @throws SodiumException
     */
   
public static function encodeLocal(SymmetricKey $key): string
   
{
        if (
Binary::safeStrlen($key->raw()) < 32) {
            throw new
PaserkException("Key is too short");
        }
       
$version = $key->getProtocol();
        return
self::encode($version, (new Local($version))->encode($key));
    }

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