PHP Classes

File: tests/Types/SecretPWTest.php

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

Contents

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

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

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

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

    public function
testSecretPW()
    {
       
$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 SecretPW($password, $testConfig, $v);
           
$asym = AsymmetricSecretKey::generate($v);
           
$wrapped = $wrapper->encode($asym);
           
/** @var AsymmetricSecretKey $unwrap */
           
$unwrap = $wrapper->decode($wrapped);
           
$this->assertSame(
               
$asym->encode(),
               
$unwrap->encode()
            );
        }
    }
}