Get rid of func_get_args()

This commit is contained in:
Sokolovskyy Roman 2017-11-21 09:36:28 +01:00
parent 3065d24b0d
commit ee8f5e9769
7 changed files with 33 additions and 43 deletions

View File

@ -165,13 +165,12 @@ abstract class Strings
/**
* Create SSH2-style string
*
* @param mixed $input..
* @param $elements[]
* @access public
* @return mixed
*/
public static function packSSH2()
public static function packSSH2(...$elements)
{
$elements = func_get_args();
$format = $elements[0];
array_shift($elements);
if (strlen($format) != count($elements)) {

View File

@ -650,12 +650,13 @@ abstract class SymmetricKey
* @see Crypt/Hash.php
* @param string $password
* @param string $method
* @param $func_args[]
* @throws \LengthException if pbkdf1 is being used and the derived key length exceeds the hash length
* @return bool
* @access public
* @internal Could, but not must, extend by the child Crypt_* class
*/
public function setPassword($password, $method = 'pbkdf2')
public function setPassword($password, $method = 'pbkdf2', ...$func_args)
{
$key = '';
@ -664,23 +665,21 @@ abstract class SymmetricKey
case 'pkcs12': // from https://tools.ietf.org/html/rfc7292#appendix-B.2
case 'pbkdf1':
case 'pbkdf2':
$func_args = func_get_args();
// Hash function
$hash = isset($func_args[2]) ? strtolower($func_args[2]) : 'sha1';
$hash = isset($func_args[0]) ? strtolower($func_args[0]) : 'sha1';
$hashObj = new Hash();
$hashObj->setHash($hash);
// WPA and WPA2 use the SSID as the salt
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
$salt = isset($func_args[1]) ? $func_args[1] : $this->password_default_salt;
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
$count = isset($func_args[4]) ? $func_args[4] : 1000;
$count = isset($func_args[2]) ? $func_args[2] : 1000;
// Keylength
if (isset($func_args[5])) {
$dkLen = $func_args[5];
if (isset($func_args[3])) {
$dkLen = $func_args[3];
} else {
$key_length = $this->explicit_key_length !== false ? $this->explicit_key_length : $this->key_length;
$dkLen = $method == 'pbkdf1' ? 2 * $key_length : $key_length;

View File

@ -182,14 +182,14 @@ class DSA extends AsymmetricKey
* - 'privatekey': The private key.
* - 'publickey': The public key.
*
* @param $args[]
* @access public
* @return array|DSA
*/
static function createKey()
static function createKey(...$args)
{
self::initialize_static_variables();
$args = func_get_args();
if (count($args) == 2 && is_int($args[0]) && is_int($args[1])) {
$private = self::createParameters($args[0], $args[1]);
} else if (count($args) == 1 && $args[0] instanceof DSA) {

View File

@ -3478,12 +3478,13 @@ class X509
/**
* Set the domain name's which the cert is to be valid for
*
* @param $domains[]
* @access public
* @return array
*/
public function setDomain()
public function setDomain(...$domains)
{
$this->domains = func_get_args();
$this->domains = $domains;
$this->removeDNProp('id-at-commonName');
$this->setDNProp('id-at-commonName', $this->domains[0]);
}
@ -3492,11 +3493,11 @@ class X509
* Set the IP Addresses's which the cert is to be valid for
*
* @access public
* @param string $ipAddress optional
* @param $ipAddresses[] optional
*/
public function setIPAddress()
public function setIPAddress(...$ipAddresses)
{
$this->ipAddresses = func_get_args();
$this->ipAddresses = $ipAddresses;
/*
if (!isset($this->domains)) {
$this->removeDNProp('id-at-commonName');

View File

@ -398,15 +398,14 @@ class SFTP extends SSH2
* Login
*
* @param string $username
* @param string $password
* @param $args[] string password
* @throws \UnexpectedValueException on receipt of unexpected packets
* @return bool
* @access public
*/
public function login($username)
public function login($username, ...$args)
{
$args = func_get_args();
if (!call_user_func_array([&$this, 'sublogin'], $args)) {
if (!$this->sublogin($username, ...$args)) {
return false;
}
@ -1071,12 +1070,12 @@ class SFTP extends SSH2
* $sftp->setListOrder();
* Don't do any sort of sorting
*
* @param $args[]
* @access public
*/
public function setListOrder()
public function setListOrder(...$args)
{
$this->sortOptions = [];
$args = func_get_args();
if (empty($args)) {
return;
}

View File

@ -1359,12 +1359,11 @@ class SSH1
* named constants from it, using the value as the name of the constant and the index as the value of the constant.
* If any of the constants that would be defined already exists, none of the constants will be defined.
*
* @param array $array
* @param $args[]
* @access private
*/
private function define_array()
private function define_array(...$args)
{
$args = func_get_args();
foreach ($args as $arg) {
foreach ($arg as $key => $value) {
if (!defined($value)) {

View File

@ -2098,29 +2098,26 @@ class SSH2
* The $password parameter can be a plaintext password, a \phpseclib\Crypt\RSA object or an array
*
* @param string $username
* @param mixed $password
* @param mixed $...
* @param $args[] param mixed $password
* @return bool
* @see self::_login()
* @access public
*/
public function login($username)
public function login($username, ...$args)
{
$args = func_get_args();
return call_user_func_array([&$this, 'sublogin'], $args);
return $this->sublogin($username, ...$args);
}
/**
* Login Helper
*
* @param string $username
* @param mixed $password
* @param mixed $...
* @param $args[] param mixed $password
* @return bool
* @see self::_login_helper()
* @access private
*/
protected function sublogin($username)
protected function sublogin($username, ...$args)
{
if (!($this->bitmap & self::MASK_CONSTRUCTOR)) {
if (!$this->connect()) {
@ -2128,7 +2125,6 @@ class SSH2
}
}
$args = array_slice(func_get_args(), 1);
if (empty($args)) {
return $this->login_helper($username);
}
@ -2375,15 +2371,13 @@ class SSH2
/**
* Handle the keyboard-interactive requests / responses.
*
* @param string $responses...
* @param $responses[]
* @return bool
* @throws \RuntimeException on connection error
* @access private
*/
private function keyboard_interactive_process()
private function keyboard_interactive_process(...$responses)
{
$responses = func_get_args();
if (strlen($this->last_interactive_response)) {
$response = $this->last_interactive_response;
} else {
@ -4058,12 +4052,11 @@ class SSH2
* named constants from it, using the value as the name of the constant and the index as the value of the constant.
* If any of the constants that would be defined already exists, none of the constants will be defined.
*
* @param array $array
* @param $args[]
* @access protected
*/
protected function define_array()
protected function define_array(...$args)
{
$args = func_get_args();
foreach ($args as $arg) {
foreach ($arg as $key => $value) {
if (!defined($value)) {