|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The RandomLib library for securely generating random numbers and strings in PHP |
|
5
|
|
|
* |
|
6
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
7
|
|
|
* @copyright 2011 The Authors |
|
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
9
|
|
|
* @version Build @@version@@ |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace RandomLib\Mixer; |
|
12
|
|
|
|
|
13
|
|
|
use SecurityLib\Strength; |
|
14
|
|
|
|
|
15
|
|
View Code Duplication |
class McryptRijndael128Test extends \PHPUnit_Framework_TestCase |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
public static function provideMix() |
|
18
|
|
|
{ |
|
19
|
|
|
$data = array( |
|
20
|
|
|
array(array(), ''), |
|
21
|
|
|
array(array('', ''), ''), |
|
22
|
|
|
array(array('a'), '61'), |
|
23
|
|
|
array(array('a', 'b'), '6a'), |
|
24
|
|
|
array(array('aa', 'ba'), '688d'), |
|
25
|
|
|
array(array('ab', 'bb'), 'f8bc'), |
|
26
|
|
|
array(array('aa', 'bb'), 'a0f3'), |
|
27
|
|
|
array(array('aa', 'bb', 'cc'), '87c3'), |
|
28
|
|
|
array(array('aabbcc', 'bbccdd', 'ccddee'), '7cf2273e46c7'), |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
return $data; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
if (!extension_loaded('mcrypt')) { |
|
37
|
|
|
$this->markTestSkipped('mcrypt extension is not available'); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testConstructWithoutArgument() |
|
42
|
|
|
{ |
|
43
|
|
|
$hash = new McryptRijndael128(); |
|
44
|
|
|
$this->assertTrue($hash instanceof \RandomLib\Mixer); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetStrength() |
|
48
|
|
|
{ |
|
49
|
|
|
$strength = new Strength(Strength::HIGH); |
|
50
|
|
|
$actual = McryptRijndael128::getStrength(); |
|
51
|
|
|
$this->assertEquals($actual, $strength); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testTest() |
|
55
|
|
|
{ |
|
56
|
|
|
$actual = McryptRijndael128::test(); |
|
57
|
|
|
$this->assertTrue($actual); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @dataProvider provideMix |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testMix($parts, $result) |
|
64
|
|
|
{ |
|
65
|
|
|
$mixer = new McryptRijndael128(); |
|
66
|
|
|
$actual = $mixer->mix($parts); |
|
67
|
|
|
$this->assertEquals($result, bin2hex($actual)); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.