forked from phpseclib/phpseclib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply coding guidelines (with exceptions) to the tests directory.
- Loading branch information
Showing
16 changed files
with
636 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="phpseclib Test Standard"> | ||
|
||
<description>phpseclib coding standard for tests</description> | ||
|
||
<!-- In general rules that apply to library code also apply to tests. --> | ||
<rule ref="./code-sniffer-ruleset.xml"> | ||
<!-- Exceptions to the library coding standard follow. --> | ||
|
||
<!-- We do not care too much about method, class and file documentation, | ||
but having @author, @copyright and @license tags would be nice. | ||
The following configuration does not check for these tags, but | ||
complains if the file doc block is missing completely. --> | ||
<exclude name="PEAR.Commenting.ClassComment" /> | ||
<exclude name="PEAR.Commenting.FunctionComment" /> | ||
<exclude name="PEAR.Commenting.FileComment.MissingTag" /> | ||
<exclude name="PEAR.Commenting.FileComment.MissingVersion" /> | ||
<exclude name="PEAR.Commenting.FileComment.SpacingBeforeTags" /> | ||
</rule> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,72 @@ | ||
<?php | ||
/** | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXIII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXIII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
*/ | ||
|
||
class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase | ||
{ | ||
// String intented | ||
protected $modes = array( | ||
'CRYPT_AES_MODE_CTR', | ||
'CRYPT_AES_MODE_OFB', | ||
'CRYPT_AES_MODE_CFB', | ||
); | ||
// String intented | ||
protected $modes = array( | ||
'CRYPT_AES_MODE_CTR', | ||
'CRYPT_AES_MODE_OFB', | ||
'CRYPT_AES_MODE_CFB', | ||
); | ||
|
||
protected $plaintexts = array( | ||
'', | ||
'12345678901234567', // https://github.com/phpseclib/phpseclib/issues/39 | ||
"\xDE\xAD\xBE\xAF", | ||
':-):-):-):-):-):-)', // https://github.com/phpseclib/phpseclib/pull/43 | ||
); | ||
protected $plaintexts = array( | ||
'', | ||
'12345678901234567', // https://github.com/phpseclib/phpseclib/issues/39 | ||
"\xDE\xAD\xBE\xAF", | ||
':-):-):-):-):-):-)', // https://github.com/phpseclib/phpseclib/pull/43 | ||
); | ||
|
||
protected $ivs = array( | ||
'', | ||
'test123', | ||
); | ||
protected $ivs = array( | ||
'', | ||
'test123', | ||
); | ||
|
||
protected $keys = array( | ||
'', | ||
':-8', // https://github.com/phpseclib/phpseclib/pull/43 | ||
'FOOBARZ', | ||
); | ||
protected $keys = array( | ||
'', | ||
':-8', // https://github.com/phpseclib/phpseclib/pull/43 | ||
'FOOBARZ', | ||
); | ||
|
||
/** | ||
* Produces all combinations of test values. | ||
* | ||
* @return array | ||
*/ | ||
public function allCombinations() | ||
{ | ||
$result = array(); | ||
/** | ||
* Produces all combinations of test values. | ||
* | ||
* @return array | ||
*/ | ||
public function allCombinations() | ||
{ | ||
$result = array(); | ||
|
||
foreach ($this->modes as $mode) | ||
foreach ($this->plaintexts as $plaintext) | ||
foreach ($this->ivs as $iv) | ||
foreach ($this->keys as $key) | ||
$result[] = array($mode, $plaintext, $iv, $key); | ||
// @codingStandardsIgnoreStart | ||
foreach ($this->modes as $mode) | ||
foreach ($this->plaintexts as $plaintext) | ||
foreach ($this->ivs as $iv) | ||
foreach ($this->keys as $key) | ||
$result[] = array($mode, $plaintext, $iv, $key); | ||
// @codingStandardsIgnoreEnd | ||
|
||
return $result; | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* @dataProvider allCombinations | ||
*/ | ||
public function testEncryptDecrypt($mode, $plaintext, $iv, $key) | ||
{ | ||
$aes = new Crypt_AES(constant($mode)); | ||
$aes->enableContinuousBuffer(); | ||
$aes->setIV($iv); | ||
$aes->setKey($key); | ||
/** | ||
* @dataProvider allCombinations | ||
*/ | ||
public function testEncryptDecrypt($mode, $plaintext, $iv, $key) | ||
{ | ||
$aes = new Crypt_AES(constant($mode)); | ||
$aes->enableContinuousBuffer(); | ||
$aes->setIV($iv); | ||
$aes->setKey($key); | ||
|
||
$actual = ''; | ||
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i) | ||
{ | ||
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i])); | ||
} | ||
$actual = ''; | ||
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i) { | ||
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i])); | ||
} | ||
|
||
$this->assertEquals($plaintext, $actual); | ||
} | ||
$this->assertEquals($plaintext, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
<?php | ||
/** | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXIII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXIII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
*/ | ||
|
||
require_once 'Crypt/AES.php'; | ||
|
||
abstract class Crypt_AES_TestCase extends PhpseclibTestCase | ||
{ | ||
static public function setUpBeforeClass() | ||
{ | ||
require_once('Crypt/AES.php'); | ||
|
||
if (!defined('CRYPT_AES_MODE')) | ||
{ | ||
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL); | ||
} | ||
} | ||
static public function setUpBeforeClass() | ||
{ | ||
if (!defined('CRYPT_AES_MODE')) { | ||
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL); | ||
} | ||
} | ||
|
||
public function setUp() | ||
{ | ||
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL) | ||
{ | ||
$this->markTestSkipped('Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.'); | ||
} | ||
} | ||
public function setUp() | ||
{ | ||
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL) { | ||
$this->markTestSkipped( | ||
'Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.' | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
<?php | ||
/** | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
*/ | ||
|
||
class Crypt_Hash_MD5Test extends Crypt_Hash_TestCase | ||
{ | ||
public function getInstance() | ||
{ | ||
return new Crypt_Hash('md5'); | ||
} | ||
public function getInstance() | ||
{ | ||
return new Crypt_Hash('md5'); | ||
} | ||
|
||
/** | ||
* @dataProvider hashData() | ||
*/ | ||
public function testHash($message, $result) | ||
{ | ||
$this->assertHashesTo($this->getInstance(), $message, $result); | ||
} | ||
/** | ||
* @dataProvider hashData() | ||
*/ | ||
public function testHash($message, $result) | ||
{ | ||
$this->assertHashesTo($this->getInstance(), $message, $result); | ||
} | ||
|
||
static public function hashData() | ||
{ | ||
return array( | ||
array('', 'd41d8cd98f00b204e9800998ecf8427e'), | ||
array('The quick brown fox jumps over the lazy dog', '9e107d9d372bb6826bd81d3542a419d6'), | ||
array('The quick brown fox jumps over the lazy dog.', 'e4d909c290d0fb1ca068ffaddf22cbd0'), | ||
); | ||
} | ||
static public function hashData() | ||
{ | ||
return array( | ||
array('', 'd41d8cd98f00b204e9800998ecf8427e'), | ||
array('The quick brown fox jumps over the lazy dog', '9e107d9d372bb6826bd81d3542a419d6'), | ||
array('The quick brown fox jumps over the lazy dog.', 'e4d909c290d0fb1ca068ffaddf22cbd0'), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider hmacData() | ||
*/ | ||
public function testHMAC($key, $message, $result) | ||
{ | ||
$this->assertHMACsTo($this->getInstance(), $key, $message, $result); | ||
} | ||
/** | ||
* @dataProvider hmacData() | ||
*/ | ||
public function testHMAC($key, $message, $result) | ||
{ | ||
$this->assertHMACsTo($this->getInstance(), $key, $message, $result); | ||
} | ||
|
||
static public function hmacData() | ||
{ | ||
return array( | ||
array('', '', '74e6f7298a9c2d168935f58c001bad88'), | ||
array('key', 'The quick brown fox jumps over the lazy dog', '80070713463e7749b90c2dc24911e275'), | ||
); | ||
} | ||
static public function hmacData() | ||
{ | ||
return array( | ||
array('', '', '74e6f7298a9c2d168935f58c001bad88'), | ||
array('key', 'The quick brown fox jumps over the lazy dog', '80070713463e7749b90c2dc24911e275'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
<?php | ||
/** | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
* @author Andreas Fischer <[email protected]> | ||
* @copyright MMXII Andreas Fischer | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
*/ | ||
|
||
require_once 'Crypt/Hash.php'; | ||
|
||
abstract class Crypt_Hash_TestCase extends PhpseclibTestCase | ||
{ | ||
static public function setUpBeforeClass() | ||
{ | ||
require_once('Crypt/Hash.php'); | ||
|
||
if (!defined('CRYPT_HASH_MODE')) | ||
{ | ||
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL); | ||
} | ||
} | ||
static public function setUpBeforeClass() | ||
{ | ||
if (!defined('CRYPT_HASH_MODE')) { | ||
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL); | ||
} | ||
} | ||
|
||
public function setUp() | ||
{ | ||
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL) | ||
{ | ||
$this->markTestSkipped('Skipping test because CRYPT_HASH_MODE is not defined as CRYPT_HASH_MODE_INTERNAL.'); | ||
} | ||
} | ||
public function setUp() | ||
{ | ||
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL) { | ||
$this->markTestSkipped( | ||
'Skipping test because CRYPT_HASH_MODE is not defined as CRYPT_HASH_MODE_INTERNAL.' | ||
); | ||
} | ||
} | ||
|
||
protected function assertHashesTo(Crypt_Hash $hash, $message, $expected) | ||
{ | ||
$this->assertEquals( | ||
strtolower($expected), | ||
bin2hex($hash->hash($message)), | ||
sprintf("Failed asserting that '%s' hashes to '%s'.", $message, $expected) | ||
); | ||
} | ||
protected function assertHashesTo(Crypt_Hash $hash, $message, $expected) | ||
{ | ||
$this->assertEquals( | ||
strtolower($expected), | ||
bin2hex($hash->hash($message)), | ||
sprintf("Failed asserting that '%s' hashes to '%s'.", $message, $expected) | ||
); | ||
} | ||
|
||
protected function assertHMACsTo(Crypt_Hash $hash, $key, $message, $expected) | ||
{ | ||
$hash->setKey($key); | ||
protected function assertHMACsTo(Crypt_Hash $hash, $key, $message, $expected) | ||
{ | ||
$hash->setKey($key); | ||
|
||
$this->assertEquals( | ||
strtolower($expected), | ||
bin2hex($hash->hash($message)), | ||
sprintf("Failed asserting that '%s' HMACs to '%s' with key '%s'.", $message, $expected, $key) | ||
); | ||
} | ||
$this->assertEquals( | ||
strtolower($expected), | ||
bin2hex($hash->hash($message)), | ||
sprintf( | ||
"Failed asserting that '%s' HMACs to '%s' with key '%s'.", | ||
$message, | ||
$expected, | ||
$key | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.