Completed
Pull Request — master (#2)
by thomas
72:23 queued 66:26
created

KeyDerivationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeyDerivationVectors() 0 11 2
A testKeyDerivation() 0 5 1
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');
0 ignored issues
show
Documentation introduced by
$output is of type object<BitWasp\Buffertools\BufferInterface>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
}
40