Fix mode mapping order and param type

This commit is contained in:
Jukka Svahn 2019-08-24 02:06:45 +03:00
parent b89c488f43
commit 488433e10f
7 changed files with 26 additions and 24 deletions

View File

@ -288,17 +288,17 @@ class Blowfish extends BlockCipher
/**
* Default Constructor.
*
* @param int $mode
* @param int|string $mode
* @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
parent::__construct($mode);
if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
}
parent::__construct($mode);
}
/**

View File

@ -602,20 +602,22 @@ abstract class SymmetricKey
*
* - gcm
*
* @param string $mode
* @param string|int $mode
* @access public
* @throws BadModeException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
$mode = strtolower($mode);
// necessary because of 5.6 compatibility; we can't do isset(self::MODE_MAP[$mode]) in 5.6
$map = self::MODE_MAP;
if (!isset($map[$mode])) {
throw new BadModeException('No valid mode has been specified');
}
if (!is_int($mode) || !in_array($mode, self::MODE_MAP, true)) {
$mode = strtolower($mode);
// necessary because of 5.6 compatibility; we can't do isset(self::MODE_MAP[$mode]) in 5.6
$map = self::MODE_MAP;
if (!isset($map[$mode])) {
throw new BadModeException('No valid mode has been specified');
}
$mode = self::MODE_MAP[$mode];
$mode = self::MODE_MAP[$mode];
}
// $mode dependent settings
switch ($mode) {

View File

@ -584,17 +584,17 @@ class DES extends BlockCipher
/**
* Default Constructor.
*
* @param int $mode
* @param int|string $mode
* @access public
* @throws BadModeException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
parent::__construct($mode);
if ($mode == self::MODE_STREAM) {
throw new BadModeException('Block ciphers cannot be ran in stream mode');
}
parent::__construct($mode);
}
/**

View File

@ -265,17 +265,17 @@ class RC2 extends BlockCipher
/**
* Default Constructor.
*
* @param int $mode
* @param int|string $mode
* @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
parent::__construct($mode);
if ($mode == self::MODE_STREAM) {
throw new BadModeException('Block ciphers cannot be ran in stream mode');
}
parent::__construct($mode);
}
/**

View File

@ -168,17 +168,17 @@ class Rijndael extends BlockCipher
/**
* Default Constructor.
*
* @param int $mode
* @param int|string $mode
* @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
parent::__construct($mode);
if ($mode == self::MODE_STREAM) {
throw new BadModeException('Block ciphers cannot be ran in stream mode');
}
parent::__construct($mode);
}
/**

View File

@ -138,7 +138,7 @@ class TripleDES extends DES
*
* @see \phpseclib\Crypt\DES::__construct()
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
* @param int $mode
* @param int|string $mode
* @access public
*/
public function __construct($mode)

View File

@ -374,17 +374,17 @@ class Twofish extends BlockCipher
/**
* Default Constructor.
*
* @param int $mode
* @param int|string $mode
* @access public
* @throws BadModeException if an invalid / unsupported mode is provided
*/
public function __construct($mode)
{
parent::__construct($mode);
if ($mode == self::MODE_STREAM) {
throw new BadModeException('Block ciphers cannot be ran in stream mode');
}
parent::__construct($mode);
}
/**