PHP Classes

File: tests/Operations/PKETest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PASERK PHP   tests/Operations/PKETest.php   Download  
File: tests/Operations/PKETest.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,250 bytes
 

Contents

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

use
ParagonIE\Paserk\Operations\Key\SealingPublicKey;
use
ParagonIE\Paserk\Operations\Key\SealingSecretKey;
use
ParagonIE\Paserk\Operations\PKE;
use
ParagonIE\Paseto\Keys\SymmetricKey;
use
ParagonIE\Paseto\Protocol\{
   
Version3,
   
Version4
};
use
ParagonIE\Paseto\ProtocolInterface;
use
PHPUnit\Framework\TestCase;

/**
 * Class PKETest
 * @package ParagonIE\Paserk\Tests\Operations
 *
 * @covers PKE
 */
class PKETest extends TestCase
{
   
/** @var ProtocolInterface[] */
   
protected array $versions = [];

    public function
setUp(): void
   
{
       
$this->versions = [
            new
Version3(),
            new
Version4()
        ];
    }

    public function
testPKE()
    {
        foreach (
$this->versions as $v) {
           
$key = SymmetricKey::generate($v);
           
$sk = SealingSecretKey::generate($v);
           
/** @var SealingPublicKey $pk */
           
$pk = $sk->getPublicKey();

           
$pke = new PKE($v);
           
$sealed = $pke->seal($key, $pk);
           
$opened = $pke->unseal($sealed, $sk);
           
$this->assertSame(
               
$opened->encode(),
               
$key->encode()
            );
        }
    }
}