Skip to content

Commit 23ea12d

Browse files
committed
More testing coverage work
1 parent acf8fdb commit 23ea12d

File tree

12 files changed

+371
-215
lines changed

12 files changed

+371
-215
lines changed

lib/CryptLib/Encryption/Symmetric.php

Lines changed: 0 additions & 213 deletions
This file was deleted.

lib/CryptLib/Key/Derivation/PBKDF/Schneier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function derive($password, $salt, $iterations, $length) {
4040
* @return string The signature for this instance
4141
*/
4242
public function getSignature() {
43-
return 'schneier-'.$this->hash->getName();
43+
return 'schneier-'.$this->hash;
4444
}
4545

4646
}

lib/CryptLib/Key/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Factory extends \CryptLib\Core\AbstractFactory {
4545
*/
4646
public function __construct() {
4747
$this->loadPBKDF();
48-
//$this->loadKDF();
48+
$this->loadKDF();
4949
//$this->loadSymmetricGenerators();
5050
}
5151

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use CryptLib\Key\Derivation\KDF\KDF1;
4+
5+
class Unit_Key_Derivation_KDF_KDF1Test extends PHPUnit_Framework_TestCase {
6+
7+
public static function provideTestDerive() {
8+
return array(
9+
array('password', 20, '', '3f5d118200e8061deb178398380118bef891f395'),
10+
array('password', 20, 'something', '46f4a5e6828a031d5db234045f836fd8a6f3ba17'),
11+
);
12+
}
13+
14+
/**
15+
* @covers CryptLib\Key\Derivation\KDF\KDF1
16+
* @covers CryptLib\Key\Derivation\AbstractDerivation
17+
*/
18+
public function testConstruct() {
19+
$pb = new KDF1();
20+
$this->assertTrue($pb instanceof KDF1);
21+
}
22+
23+
/**
24+
* @covers CryptLib\Key\Derivation\KDF\KDF1
25+
* @dataProvider provideTestDerive
26+
* @group slow
27+
*/
28+
public function testDerive($p, $len, $data, $expect) {
29+
$pb = new KDF1();
30+
$actual = $pb->derive($p, $len, $data);
31+
$actual = bin2hex($actual);
32+
$this->assertEquals($expect, $actual);
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use CryptLib\Key\Derivation\KDF\KDF2;
4+
5+
class Unit_Key_Derivation_KDF_KDF2Test extends PHPUnit_Framework_TestCase {
6+
7+
public static function provideTestDerive() {
8+
return array(
9+
array('password', 20, '', 'b4de807b408717196ca96c0c114e0f881f0b6ef8'),
10+
array('password', 20, 'something', '96a482a79360192704f20716016c8850890db856'),
11+
);
12+
}
13+
14+
/**
15+
* @covers CryptLib\Key\Derivation\KDF\KDF2
16+
* @covers CryptLib\Key\Derivation\AbstractDerivation
17+
*/
18+
public function testConstruct() {
19+
$pb = new KDF2();
20+
$this->assertTrue($pb instanceof KDF2);
21+
}
22+
23+
/**
24+
* @covers CryptLib\Key\Derivation\KDF\KDF2
25+
* @dataProvider provideTestDerive
26+
* @group slow
27+
*/
28+
public function testDerive($p, $len, $data, $expect) {
29+
$pb = new KDF2();
30+
$actual = $pb->derive($p, $len, $data);
31+
$actual = bin2hex($actual);
32+
$this->assertEquals($expect, $actual);
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use CryptLib\Key\Derivation\KDF\KDF3;
4+
5+
class Unit_Key_Derivation_KDF_KDF3Test extends PHPUnit_Framework_TestCase {
6+
7+
public static function provideTestDerive() {
8+
return array(
9+
array('password', 20, '', '20c74d01389f8cbfba727e951e62fdbd206019c1'),
10+
array('password', 20, 'something', 'ad952bdfebba1bb06299fca88495e1d404e0c780'),
11+
);
12+
}
13+
14+
/**
15+
* @covers CryptLib\Key\Derivation\KDF\KDF3
16+
* @covers CryptLib\Key\Derivation\AbstractDerivation
17+
*/
18+
public function testConstruct() {
19+
$pb = new KDF3();
20+
$this->assertTrue($pb instanceof KDF3);
21+
}
22+
23+
/**
24+
* @covers CryptLib\Key\Derivation\KDF\KDF3
25+
* @dataProvider provideTestDerive
26+
* @group slow
27+
*/
28+
public function testDerive($p, $len, $data, $expect) {
29+
$pb = new KDF3();
30+
$actual = $pb->derive($p, $len, $data);
31+
$actual = bin2hex($actual);
32+
$this->assertEquals($expect, $actual);
33+
}
34+
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use CryptLib\Key\Derivation\PBKDF\BCrypt;
4+
5+
class Unit_Key_Derivation_PBKDF_BCryptTest extends PHPUnit_Framework_TestCase {
6+
7+
public static function provideTestDerive() {
8+
return array(
9+
array('password', 'salt', 1, 20, '$2a$04$c2FsdA//$$$$$$$$$$$$$.s/cqDDqZHdfICtEE.ehrDKzSnRzlgJ2'),
10+
array('password', 'somelongsaltstringherewithmore', 1, 20, '$2a$04$c29tZWxvbmdzYWx0c3RyaODWXyN.i8AWP0fApQMGEDItVQbPIti6u'),
11+
);
12+
}
13+
14+
/**
15+
* @covers CryptLib\Key\Derivation\PBKDF\BCrypt
16+
* @covers CryptLib\Key\Derivation\AbstractDerivation
17+
*/
18+
public function testConstruct() {
19+
$pb = new BCrypt();
20+
$this->assertTrue($pb instanceof BCrypt);
21+
}
22+
23+
/**
24+
* @covers CryptLib\Key\Derivation\PBKDF\BCrypt
25+
* @dataProvider provideTestDerive
26+
* @group slow
27+
*/
28+
public function testDerive($p, $s, $c, $len, $expect) {
29+
$pb = new BCrypt();
30+
$actual = $pb->derive($p, $s, $c, $len);
31+
$this->assertEquals($expect, $actual);
32+
}
33+
34+
/**
35+
* @covers CryptLib\Key\Derivation\PBKDF\BCrypt
36+
*/
37+
public function testGetSignature() {
38+
$pb = new BCrypt();
39+
$this->assertEquals('bcrypt', $pb->getSignature());
40+
}
41+
}

0 commit comments

Comments
 (0)