mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-04 18:48:24 +01:00
Merge branch 'master' into php5
* master:
Fixed classname of test
Fixed some wrong @see annotations
Fixed /e preg_replace modifier exactly like in 0dc8b27a6a
Added Net_SSH1::_format_log test
This commit is contained in:
commit
060ae325b7
@ -434,6 +434,30 @@ class Net_SSH1
|
|||||||
*/
|
*/
|
||||||
var $curTimeout;
|
var $curTimeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log Boundary
|
||||||
|
*
|
||||||
|
* @see Net_SSH1::_format_log
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $log_boundary = ':';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log Long Width
|
||||||
|
*
|
||||||
|
* @see Net_SSH1::_format_log
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $log_long_width = 65;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log Short Width
|
||||||
|
*
|
||||||
|
* @see Net_SSH1::_format_log
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $log_short_width = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor.
|
* Default Constructor.
|
||||||
*
|
*
|
||||||
@ -1351,8 +1375,6 @@ class Net_SSH1
|
|||||||
*/
|
*/
|
||||||
function _format_log($message_log, $message_number_log)
|
function _format_log($message_log, $message_number_log)
|
||||||
{
|
{
|
||||||
static $boundary = ':', $long_width = 65, $short_width = 16;
|
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
for ($i = 0; $i < count($message_log); $i++) {
|
for ($i = 0; $i < count($message_log); $i++) {
|
||||||
$output.= $message_number_log[$i] . "\r\n";
|
$output.= $message_number_log[$i] . "\r\n";
|
||||||
@ -1362,19 +1384,13 @@ class Net_SSH1
|
|||||||
if (strlen($current_log)) {
|
if (strlen($current_log)) {
|
||||||
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
||||||
}
|
}
|
||||||
$fragment = $this->_string_shift($current_log, $short_width);
|
$fragment = $this->_string_shift($current_log, $this->log_short_width);
|
||||||
$hex = substr(
|
$hex = substr(preg_replace_callback('#.#s', array($this, '_format_log_helper'), $fragment), strlen($this->log_boundary));
|
||||||
preg_replace(
|
|
||||||
'#(.)#es',
|
|
||||||
'"' . $boundary . '" . str_pad(dechex(ord(substr("\\1", -1))), 2, "0", STR_PAD_LEFT)',
|
|
||||||
$fragment),
|
|
||||||
strlen($boundary)
|
|
||||||
);
|
|
||||||
// replace non ASCII printable characters with dots
|
// replace non ASCII printable characters with dots
|
||||||
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
||||||
// also replace < with a . since < messes up the output on web browsers
|
// also replace < with a . since < messes up the output on web browsers
|
||||||
$raw = preg_replace('#[^\x20-\x7E]|<#', '.', $fragment);
|
$raw = preg_replace('#[^\x20-\x7E]|<#', '.', $fragment);
|
||||||
$output.= str_pad($hex, $long_width - $short_width, ' ') . $raw . "\r\n";
|
$output.= str_pad($hex, $this->log_long_width - $this->log_short_width, ' ') . $raw . "\r\n";
|
||||||
$j++;
|
$j++;
|
||||||
} while (strlen($current_log));
|
} while (strlen($current_log));
|
||||||
$output.= "\r\n";
|
$output.= "\r\n";
|
||||||
@ -1383,6 +1399,20 @@ class Net_SSH1
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for _format_log
|
||||||
|
*
|
||||||
|
* For use with preg_replace_callback()
|
||||||
|
*
|
||||||
|
* @param Array $matches
|
||||||
|
* @access private
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
function _format_log_helper($matches)
|
||||||
|
{
|
||||||
|
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the server key public exponent
|
* Return the server key public exponent
|
||||||
*
|
*
|
||||||
|
41
tests/Net/SSH1Test.php
Normal file
41
tests/Net/SSH1Test.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Marc Scholten <marc@pedigital.de>
|
||||||
|
* @copyright MMXIII Marc Scholten
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Net_SSH1Test extends PhpseclibTestCase
|
||||||
|
{
|
||||||
|
public function formatLogDataProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array('hello world'),
|
||||||
|
array('<--'),
|
||||||
|
"<--\r\n00000000 68:65:6c:6c:6f:20:77:6f:72:6c:64 hello world\r\n\r\n"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('hello', 'world'),
|
||||||
|
array('<--', '<--'),
|
||||||
|
"<--\r\n00000000 68:65:6c:6c:6f hello\r\n\r\n" .
|
||||||
|
"<--\r\n00000000 77:6f:72:6c:64 world\r\n\r\n"
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider formatLogDataProvider
|
||||||
|
*/
|
||||||
|
public function testFormatLog(array $message_log, array $message_number_log, $expected)
|
||||||
|
{
|
||||||
|
$ssh = $this->getMockBuilder('Net_SSH1')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(null)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$result = $ssh->_format_log($message_log, $message_number_log);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user