HeaderBlobTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testValues() 0 20 1
1
<?php
2
3
namespace Btccom\JustEncrypt\Test;
4
5
use BitWasp\Buffertools\Buffer;
6
use Btccom\JustEncrypt\HeaderBlob;
7
8
class HeaderBlobTest extends AbstractTestCase
9
{
10
    public function testValues()
11
    {
12
13
        $salt = new Buffer(random_bytes(4));
14
        $iterations = 10;
15
16
        $pw = new Buffer("passwords can be long, and even consist of unprintable characters \x01\x90");
17
18
        $headerBlob = new HeaderBlob($salt->getSize(), $salt, $iterations);
19
        $this->assertEquals($salt->getSize(), $headerBlob->getSaltLen());
20
        $this->assertEquals($salt->getBinary(), $headerBlob->getSalt()->getBinary());
21
        $this->assertEquals($iterations, $headerBlob->getIterations());
22
        $this->assertTrue($salt->equals($headerBlob->getSalt()));
23
24
        $expectedBinary = pack('c', $salt->getSize()) . $salt->getBinary() . pack('V', $headerBlob->getIterations());
25
        $this->assertEquals($expectedBinary, $headerBlob->getBinary());
26
27
        $expectedKey = hash_pbkdf2('sha512', $pw->getBinary(), $salt->getBinary(), $iterations, 32, true);
28
        $this->assertEquals($expectedKey, $headerBlob->deriveKey($pw)->getBinary());
29
    }
30
}
31