KeyDerivationTest::getKeyDerivationVectors()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Btccom\JustEncrypt\Test;
4
5
use BitWasp\Buffertools\Buffer;
6
use BitWasp\Buffertools\BufferInterface;
7
use Btccom\JustEncrypt\HeaderBlob;
8
use Btccom\JustEncrypt\KeyDerivation;
9
10
class KeyDerivationTest extends AbstractTestCase
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getKeyDerivationVectors()
16
    {
17
        return array_map(function (array $row) {
18
            if (isset($row['password_utf8'])) {
19
                $password = new Buffer($row['password_utf8']);
20
            } else {
21
                $password = Buffer::hex($row['password']);
22
            }
23
            return [$password, Buffer::hex($row['salt']), $row['iterations'], Buffer::hex($row['output'])];
24
        }, $this->getTestVectors()['keyderivation']);
25
    }
26
27
    /**
28
     * @param BufferInterface $password
29
     * @param BufferInterface $salt
30
     * @param BufferInterface $expectedOutput
31
     * @param int $iterations
32
     * @dataProvider getKeyDerivationVectors
33
     */
34
    public function testKeyDerivation(BufferInterface $password, BufferInterface $salt, $iterations, BufferInterface $expectedOutput)
35
    {
36
        $output = KeyDerivation::compute($password, $salt, $iterations);
37
        $this->assertTrue($expectedOutput->equals($output), 'key derivation produces same output');
38
    }
39
}
40