1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\DESCrypt;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class DESCryptTest extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35:
36: array ("U*U*U*U*", 'CCNf8Sbh3HDfQ'),
37: array ("U*U***U", 'CCX.K.MFy4Ois'),
38: array ("U*U***U*", 'CC4rMpbg9AMZ.'),
39: array ("*U*U*U*U", 'XXxzOu6maQKqQ'),
40: array ("", 'SDbsugeBiC58A'),
41: );
42:
43: return $vectors;
44: }
45:
46: 47: 48: 49: 50:
51: public function invalidTestVectorProvider()
52: {
53: $vectors = array (
54: array ("", '!gAwTx2l6NADI', '*0'),
55: array ("", '*0', '*1'),
56: array ("", '*1', '*0'),
57: );
58:
59: return $vectors;
60: }
61:
62: 63: 64: 65: 66: 67: 68: 69:
70: public function validTestVectorsProduceExpectedResults($password, $hash)
71: {
72: $config = substr($hash, 0, 29);
73: $this->assertEquals($hash, DESCrypt::hash($password, $config));
74: $this->assertTrue(DESCrypt::verify($password, $hash));
75: }
76:
77: 78: 79: 80: 81: 82: 83: 84:
85: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
86: {
87: $config = substr($hash, 0, 29);
88: $this->assertEquals($errorString, DESCrypt::hash($password, $config));
89: $this->assertFalse(DESCrypt::verify($password, $hash));
90: }
91:
92: 93: 94:
95: public function genconfigAndParseconfigProduceMatchingResults()
96: {
97: $options = array (
98: 'salt' => 'C.',
99: );
100: $config = DESCrypt::genConfig($options);
101:
102: $this->assertEquals('C.', $config);
103: $this->assertSame($options, DESCrypt::parseConfig($config));
104: }
105:
106: }
107: