mirror of
https://github.com/danog/tgseclib.git
synced 2025-01-21 21:41:14 +01:00
SymmetricKey: isValidKey took ints instead of strings
This commit is contained in:
parent
e7e30cd239
commit
9d8f014748
@ -327,10 +327,10 @@ class Blowfish extends BlockCipher
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
if (version_compare(PHP_VERSION, '5.3.7') < 0 && $this->key_length != 16) {
|
||||
@ -343,7 +343,7 @@ class Blowfish extends BlockCipher
|
||||
$this->cipher_name_openssl = 'bf-' . $this->openssl_translate_mode();
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1712,10 +1712,10 @@ abstract class SymmetricKey
|
||||
*
|
||||
* @see self::__construct()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
@ -1756,6 +1756,29 @@ abstract class SymmetricKey
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for engine validity
|
||||
*
|
||||
* @see self::__construct()
|
||||
* @param string $engine
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
static $reverseMap;
|
||||
if (!isset($reverseMap)) {
|
||||
$reverseMap = array_map('strtolower', self::ENGINE_MAP);
|
||||
$reverseMap = array_flip($reverseMap);
|
||||
}
|
||||
$engine = strtolower($engine);
|
||||
if (!isset($reverseMap[$engine])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isValidEngineHelper($reverseMap[$engine]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the preferred crypt engine
|
||||
*
|
||||
@ -1816,7 +1839,7 @@ abstract class SymmetricKey
|
||||
self::ENGINE_EVAL
|
||||
];
|
||||
foreach ($candidateEngines as $engine) {
|
||||
if ($this->isValidEngine($engine)) {
|
||||
if ($this->isValidEngineHelper($engine)) {
|
||||
$this->engine = $engine;
|
||||
break;
|
||||
}
|
||||
|
@ -603,10 +603,10 @@ class DES extends BlockCipher
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
if ($this->key_length_max == 8) {
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
@ -615,7 +615,7 @@ class DES extends BlockCipher
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -284,10 +284,10 @@ class RC2 extends BlockCipher
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
@ -298,7 +298,7 @@ class RC2 extends BlockCipher
|
||||
$this->cipher_name_openssl = 'rc2-' . $this->openssl_translate_mode();
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,10 +139,10 @@ class RC4 extends StreamCipher
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
if (version_compare(PHP_VERSION, '5.3.7') >= 0) {
|
||||
@ -164,7 +164,7 @@ class RC4 extends StreamCipher
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,10 +273,10 @@ class Rijndael extends BlockCipher
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
@ -294,7 +294,7 @@ class Rijndael extends BlockCipher
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,10 +178,10 @@ class TripleDES extends DES
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
|
||||
* @param int $engine
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
protected function isValidEngineHelper($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
$this->cipher_name_openssl_ecb = 'des-ede3';
|
||||
@ -189,7 +189,7 @@ class TripleDES extends DES
|
||||
$this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode;
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
return parent::isValidEngineHelper($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -215,20 +215,20 @@ class Unit_Crypt_RC4Test extends PhpseclibTestCase
|
||||
{
|
||||
$objects = $engines = array();
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_INTERNAL);
|
||||
$temp->setPreferredEngine('internal');
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'internal';
|
||||
|
||||
if ($temp->isValidEngine(RC4::ENGINE_MCRYPT)) {
|
||||
if ($temp->isValidEngine('mcrypt')) {
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_MCRYPT);
|
||||
$temp->setPreferredEngine('mcrypt');
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'mcrypt';
|
||||
}
|
||||
|
||||
if ($temp->isValidEngine(RC4::ENGINE_OPENSSL)) {
|
||||
if ($temp->isValidEngine('openssl')) {
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_OPENSSL);
|
||||
$temp->setPreferredEngine('openssl');
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'OpenSSL';
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class Unit_Crypt_TripleDESTest extends PhpseclibTestCase
|
||||
$des->disablePadding();
|
||||
$result = $des->encrypt($plaintext);
|
||||
$plaintext = bin2hex($plaintext);
|
||||
$this->assertEquals($result, $expected, "Failed asserting that $plaintext yielded expected output in $engin engine");
|
||||
$this->assertEquals($result, $expected, "Failed asserting that $plaintext yielded expected output in $engine engine");
|
||||
}
|
||||
|
||||
public function testInnerChaining()
|
||||
|
Loading…
x
Reference in New Issue
Block a user