PHP Classes

File: tests/KeyProvider/StringProviderTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Cipher Sweet   tests/KeyProvider/StringProviderTest.php   Download  
File: tests/KeyProvider/StringProviderTest.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: 5 years ago
Size: 1,435 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\StringProvider;
use
ParagonIE\ConstantTime\Base64UrlSafe;
use
ParagonIE\ConstantTime\Hex;
use
PHPUnit\Framework\TestCase;

/**
 * Class StringProviderTest
 * @package ParagonIE\CipherSweet\Tests\KeyProvider
 */
class StringProviderTest extends TestCase
{

   
/**
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
     */
   
public function testHappyPath()
    {
       
$symmetric = \random_bytes(32);
       
$backend = new ModernCrypto();
       
$provider = new StringProvider($backend, $symmetric);
       
$this->assertInstanceOf(SymmetricKey::class, $provider->getSymmetricKey());

       
$hex = new StringProvider($backend, Hex::encode($symmetric));
       
$this->assertSame(
           
Hex::encode($provider->getSymmetricKey()->getRawKey()),
           
Hex::encode($hex->getSymmetricKey()->getRawKey()),
           
'Hex-encoded keys are not producing the same result'
       
);
       
$b64 = new StringProvider($backend, Base64UrlSafe::encode($symmetric));
       
$this->assertSame(
           
Hex::encode($provider->getSymmetricKey()->getRawKey()),
           
Hex::encode($b64->getSymmetricKey()->getRawKey()),
           
'B64-encoded keys are not producing the same result'
       
);
    }
}