EncryptionTest::getEncryptionVectors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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)
0 ignored issues
show
Unused Code introduced by
The parameter $ciphertext is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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