PHP Classes

File: tests/Types/LocalPWTest.php

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

Contents

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

use
ParagonIE\HiddenString\HiddenString;
use
ParagonIE\Paserk\Types\LocalPW;
use
ParagonIE\Paseto\Keys\SymmetricKey;
use
ParagonIE\Paseto\Protocol\{
   
Version3,
   
Version4
};
use
ParagonIE\Paseto\ProtocolInterface;
use
PHPUnit\Framework\TestCase;

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

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

    public function
testLocalPW()
    {
       
$password = new HiddenString('correct horse battery staple');
       
$testConfig = [
           
'iterations' => 1000,
           
'memlimit' => SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE,
           
'opslimit' => SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
           
'parallelism' => 1,
        ];

        foreach (
$this->versions as $v) {
           
$wrapper = new LocalPW($password, $testConfig, $v);
           
$sym = SymmetricKey::generate($v);
           
$wrapped = $wrapper->encode($sym);
           
/** @var SymmetricKey $unwrap */
           
$unwrap = $wrapper->decode($wrapped);
           
$this->assertSame(
               
$sym->encode(),
               
$unwrap->encode()
            );
        }
    }
}