PHP Classes

File: tests/Operations/Wrap/PieTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PASERK PHP   tests/Operations/Wrap/PieTest.php   Download  
File: tests/Operations/Wrap/PieTest.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: 2 years ago
Size: 2,021 bytes
 

Contents

Class file image Download
<?php
/** @noinspection PhpIllegalPsrClassPathInspection */
declare(strict_types=1);
namespace
ParagonIE\Paserk\Tests\Wrap;

use
ParagonIE\Paserk\Operations\Wrap\Pie;
use
ParagonIE\Paseto\Keys\AsymmetricSecretKey;
use
ParagonIE\Paseto\Keys\SymmetricKey;
use
ParagonIE\Paseto\Protocol\Version3;
use
ParagonIE\Paseto\Protocol\Version4;
use
PHPUnit\Framework\TestCase;

/**
 * Class PieTest
 * @package ParagonIE\Paserk\Tests\Wrap
 *
 * @covers Pie
 */
class PieTest extends TestCase
{
    protected array
$v3 = [];
    protected array
$v4 = [];

    public function
setUp(): void
   
{
       
$v3sk = AsymmetricSecretKey::generate(new Version3());
       
$v4sk = AsymmetricSecretKey::generate(new Version4());

       
$v3sym = SymmetricKey::generate(new Version3());
       
$v4sym = SymmetricKey::generate(new Version4());

       
$v3wk = SymmetricKey::generate(new Version3());
       
$v4wk = SymmetricKey::generate(new Version4());

       
$this->v3 = ['header' => 'k3', 'wk' => $v3wk, 'sk' => $v3sk, 'sym' => $v3sym];
       
$this->v4 = ['header' => 'k4', 'wk' => $v4wk, 'sk' => $v4sk, 'sym' => $v4sym];
    }

    public function
testWrapUnwrap()
    {
        foreach ([
$this->v3, $this->v4] as $vers) {
           
$pie = new Pie($vers['wk']);

           
/** @var SymmetricKey $sym */
           
$sym = $vers['sym'];
           
$header = $vers['header'] . '.local-wrap.pie.';
           
$wrapped = $pie->wrapKey($header, $sym);
           
/** @var SymmetricKey $unwrapSym */
           
$unwrapSym = $pie->unwrapKey($header . $wrapped);
           
$this->assertEquals($sym->encode(), $unwrapSym->encode());

           
/** @var AsymmetricSecretKey $sk */
           
$sk = $vers['sk'];
           
$header = $vers['header'] . '.secret-wrap.pie.';
           
$wrapped = $pie->wrapKey($header, $sk);
           
/** @var AsymmetricSecretKey $unwrapSK */
           
$unwrapSK = $pie->unwrapKey($header . $wrapped);
           
$this->assertEquals($sk->encode(), $unwrapSK->encode());
        }
    }
}