File: tests/NonceFixer.php

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  PHP PASeTo  >  tests/NonceFixer.php  >  Download  
File: tests/NonceFixer.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP PASeTo
Encrypt and decrypt data with PaSeTO protocol
Author: By
Last change:
Date: 8 months ago
Size: 1,981 bytes
 

Contents

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

use
ParagonIE\Paseto\ProtocolInterface;
use
ParagonIE\Paseto\Keys\SymmetricKey;

abstract class
NonceFixer {
    public static function
buildUnitTestEncrypt(ProtocolInterface $protocol): \Closure {
        return static function (
           
string $data,
           
SymmetricKey $key,
           
string $footer = '',
           
string $nonceForUnitTesting = ''
       
) use ($protocol): string {
            return
$protocol::__encrypt($data, $key, $footer, $nonceForUnitTesting);
        };
    }

    public static function
buildSetExplicitNonce(): \Closure {
        return function (
string $nonce) {
           
/** @noinspection Annotator */
           
$this->unitTestEncrypter = static function (ProtocolInterface $protocol) use ($nonce) {
               
$class = new class {
                    private static
$nonce;
                    private static
$protocol;

                    public static function
setNonce(string $nonce)
                    {
                       
self::$nonce = $nonce;
                    }

                    public static function
setProtocol(ProtocolInterface $protocol)
                    {
                       
self::$protocol = $protocol;
                    }

                    public static function
encrypt(
                       
string $data,
                       
SymmetricKey $key,
                       
string $footer = ''
                   
): string {
                        return
NonceFixer::buildUnitTestEncrypt(self::$protocol)->bindTo(null, self::$protocol)(
                           
$data,
                           
$key,
                           
$footer,
                           
self::$nonce
                       
);
                    }
                };

               
$class::setNonce($nonce);
               
$class::setProtocol($protocol);

                return
$class;
            };
        };
    }
}


For more information send a message to info at phpclasses dot org.