mirror of
https://github.com/danog/tgseclib.git
synced 2024-11-27 04:34:45 +01:00
Merge branch 'master' of https://github.com/phpseclib/phpseclib
This commit is contained in:
commit
4c3bf94806
71
tests/Crypt/AES/ContinuousBufferTest.php
Normal file
71
tests/Crypt/AES/ContinuousBufferTest.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Andreas Fischer <bantu@phpbb.com>
|
||||
* @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',
|
||||
);
|
||||
|
||||
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 $keys = array(
|
||||
'',
|
||||
':-8', // https://github.com/phpseclib/phpseclib/pull/43
|
||||
'FOOBARZ',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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);
|
||||
|
||||
$actual = '';
|
||||
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i)
|
||||
{
|
||||
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i]));
|
||||
}
|
||||
|
||||
$this->assertEquals($plaintext, $actual);
|
||||
}
|
||||
}
|
27
tests/Crypt/AES/TestCase.php
Normal file
27
tests/Crypt/AES/TestCase.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Andreas Fischer <bantu@phpbb.com>
|
||||
* @copyright MMXIII Andreas Fischer
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
abstract class Crypt_AES_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
require_once('Crypt/AES.php');
|
||||
|
||||
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.');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user