1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Btccom\JustEncrypt\Test; |
4
|
|
|
|
5
|
|
|
use BitWasp\Buffertools\BufferInterface; |
6
|
|
|
use BitWasp\Buffertools\Buffer; |
7
|
|
|
use Btccom\JustEncrypt\Encryption; |
8
|
|
|
|
9
|
|
|
class EncryptionTest extends AbstractTestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return array |
13
|
|
|
*/ |
14
|
|
|
public function getEncryptionVectors() |
15
|
|
|
{ |
16
|
|
|
return array_map(function (array $row) { |
17
|
|
|
return [Buffer::hex($row['password']), Buffer::hex($row['salt']), $row['iterations'], Buffer::hex($row['iv']), Buffer::hex($row['pt']), Buffer::hex($row['ct']), Buffer::hex($row['tag']), Buffer::hex($row['full'])]; |
18
|
|
|
}, $this->getTestVectors()['encryption']); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @dataProvider getEncryptionVectors |
23
|
|
|
* @param BufferInterface $password |
24
|
|
|
* @param BufferInterface $salt |
25
|
|
|
* @param int $iterations |
26
|
|
|
* @param BufferInterface $iv |
27
|
|
|
* @param BufferInterface $plaintext |
28
|
|
|
* @param BufferInterface $ciphertext |
29
|
|
|
* @param BufferInterface $tag |
30
|
|
|
* @param BufferInterface $serialized |
31
|
|
|
*/ |
32
|
|
|
public function testEncryption(BufferInterface $password, BufferInterface $salt, $iterations, BufferInterface $iv, BufferInterface $plaintext, BufferInterface $ciphertext, BufferInterface $tag, BufferInterface $serialized) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$encrypt = Encryption::encryptWithSaltAndIV($plaintext, $password, $salt, $iv, $iterations)->getBuffer(); |
35
|
|
|
$decrypted = Encryption::decrypt($encrypt, $password); |
36
|
|
|
|
37
|
|
|
$this->assertEquals($plaintext, $decrypted); |
38
|
|
|
$this->assertEquals($plaintext, Encryption::decrypt($serialized, $password)); |
39
|
|
|
$this->assertEquals($encrypt, $serialized); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.