mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 11:37:33 +00:00
Misc fixes
- make it so '' is a legit password and doesn't unset the pw to pass bantu's unit tests (unit test could have been updated too but whatever) - make it so not passing in any parameters to Crypt_RSA::setPassword() works without E_NOTICE or E_WARNING as per example in docs - add missing phpdoc headers to File_ANSI - cryan -> cyan in File_ANSI
This commit is contained in:
parent
ed67b3b68d
commit
6c4fcd34d3
@ -117,7 +117,7 @@ class Crypt_Hash {
|
||||
* @var String
|
||||
* @access private
|
||||
*/
|
||||
var $key = '';
|
||||
var $key = false;
|
||||
|
||||
/**
|
||||
* Outer XOR (Internal HMAC)
|
||||
@ -170,7 +170,7 @@ class Crypt_Hash {
|
||||
* @access public
|
||||
* @param String $key
|
||||
*/
|
||||
function setKey($key)
|
||||
function setKey($key = false)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
@ -296,7 +296,7 @@ class Crypt_Hash {
|
||||
{
|
||||
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
|
||||
|
||||
if (!empty($this->key)) {
|
||||
if (!empty($this->key) || is_string($this->key)) {
|
||||
switch ( $mode ) {
|
||||
case CRYPT_HASH_MODE_MHASH:
|
||||
$output = mhash($this->hash, $text, $this->key);
|
||||
|
@ -399,7 +399,7 @@ class Crypt_RSA {
|
||||
* @var String
|
||||
* @access private
|
||||
*/
|
||||
var $password = '';
|
||||
var $password = false;
|
||||
|
||||
/**
|
||||
* Components
|
||||
@ -695,7 +695,7 @@ class Crypt_RSA {
|
||||
return false;
|
||||
}
|
||||
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
|
||||
$encryption = (!empty($this->password)) ? 'aes256-cbc' : 'none';
|
||||
$encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none';
|
||||
$key.= $encryption;
|
||||
$key.= "\r\nComment: " . CRYPT_RSA_COMMENT . "\r\n";
|
||||
$public = pack('Na*Na*Na*',
|
||||
@ -712,7 +712,7 @@ class Crypt_RSA {
|
||||
strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'],
|
||||
strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']
|
||||
);
|
||||
if (empty($this->password)) {
|
||||
if (empty($this->password) && !is_string($this->password)) {
|
||||
$source.= pack('Na*', strlen($private), $private);
|
||||
$hashkey = 'putty-private-key-file-mac-key';
|
||||
} else {
|
||||
@ -775,7 +775,7 @@ class Crypt_RSA {
|
||||
|
||||
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
|
||||
|
||||
if (!empty($this->password)) {
|
||||
if (!empty($this->password) || is_string($this->password)) {
|
||||
$iv = $this->_random(8);
|
||||
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
|
||||
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
|
||||
@ -1347,14 +1347,14 @@ class Crypt_RSA {
|
||||
* Sets the password
|
||||
*
|
||||
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
|
||||
* Or rather, pass in $password such that empty($password) is true.
|
||||
* Or rather, pass in $password such that empty($password) && !is_string($password) is true.
|
||||
*
|
||||
* @see createKey()
|
||||
* @see loadKey()
|
||||
* @access public
|
||||
* @param String $password
|
||||
*/
|
||||
function setPassword($password)
|
||||
function setPassword($password = false)
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ class File_ANSI {
|
||||
case 33: $front = 'yellow'; break;
|
||||
case 34: $front = 'blue'; break;
|
||||
case 35: $front = 'magenta'; break;
|
||||
case 36: $front = 'cryan'; break;
|
||||
case 36: $front = 'cyan'; break;
|
||||
case 37: $front = 'white'; break;
|
||||
|
||||
case 40: $back = 'black'; break;
|
||||
@ -405,7 +405,7 @@ class File_ANSI {
|
||||
case 43: $back = 'yellow'; break;
|
||||
case 44: $back = 'blue'; break;
|
||||
case 45: $back = 'magenta'; break;
|
||||
case 46: $back = 'cryan'; break;
|
||||
case 46: $back = 'cyan'; break;
|
||||
case 47: $back = 'white'; break;
|
||||
|
||||
default:
|
||||
@ -479,6 +479,12 @@ class File_ANSI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current screen without preformating
|
||||
*
|
||||
* @access private
|
||||
* @return String
|
||||
*/
|
||||
function _getScreen()
|
||||
{
|
||||
$output = '';
|
||||
@ -496,11 +502,23 @@ class File_ANSI {
|
||||
return rtrim($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current screen
|
||||
*
|
||||
* @access public
|
||||
* @return String
|
||||
*/
|
||||
function getScreen()
|
||||
{
|
||||
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $this->_getScreen() . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current screen and the x previous lines
|
||||
*
|
||||
* @access public
|
||||
* @return String
|
||||
*/
|
||||
function getHistory()
|
||||
{
|
||||
$scrollback = '';
|
||||
|
Loading…
Reference in New Issue
Block a user