PHP Classes
elePHPant
Icontem

File: tests/KeyProvider/FileProviderTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  Cipher Sweet  >  tests/KeyProvider/FileProviderTest.php  >  Download  
File: tests/KeyProvider/FileProviderTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Cipher Sweet
Encrypt data in away that can be searched
Author: By
Last change:
Date: 6 months ago
Size: 1,327 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\CipherSweet\Tests\KeyProvider;

use
ParagonIE\CipherSweet\Backend\Key\SymmetricKey;
use
ParagonIE\CipherSweet\Backend\ModernCrypto;
use
ParagonIE\CipherSweet\KeyProvider\FileProvider;
use
ParagonIE\ConstantTime\Base32;
use
PHPUnit\Framework\TestCase;

/**
 * Class FileProviderTest
 * @package ParagonIE\CipherSweet\Tests\KeyProvider
 */
class FileProviderTest extends TestCase
{
   
/**
     * @var string $prefix
     */
   
private $prefix;

   
/**
     * @throws \SodiumException
     */
   
public function setUp()
    {
       
$this->prefix = Base32::encodeUnpadded(random_bytes(16));

       
$symmetric = \random_bytes(32);
        \
file_put_contents(
           
__DIR__ . '/files/' . $this->prefix . '.symmetric',
           
$symmetric
       
);
    }

    public function
tearDown()
    {
        \
unlink(__DIR__ . '/files/' . $this->prefix . '.symmetric');
       
parent::tearDown();
    }

   
/**
     * @throws \ParagonIE\CipherSweet\Exception\KeyProviderException
     */
   
public function testHappyPath()
    {
       
$backend = new ModernCrypto();
       
$provider = new FileProvider(
           
$backend,
           
__DIR__ . '/files/' . $this->prefix . '.symmetric'
       
);

       
$this->assertInstanceOf(SymmetricKey::class, $provider->getSymmetricKey());
    }
}