Merge pull request #554 from cnelissen/NamespaceFilePackage

Namespace file package

* cnelissen/NamespaceFilePackage:
  Namespaced classes
This commit is contained in:
Andreas Fischer 2014-12-12 17:55:44 +01:00
commit 3f912eed59
6 changed files with 287 additions and 288 deletions

View File

@ -8,24 +8,26 @@
* If you call read() in Net_SSH2 you may get {@link http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes} back.
* They'd look like chr(0x1B) . '[00m' or whatever (0x1B = ESC). They tell a
* {@link http://en.wikipedia.org/wiki/Terminal_emulator terminal emulator} how to format the characters, what
* color to display them in, etc. File_ANSI is a {@link http://en.wikipedia.org/wiki/VT100 VT100} terminal emulator.
* color to display them in, etc. \phpseclib\File\ANSI is a {@link http://en.wikipedia.org/wiki/VT100 VT100} terminal emulator.
*
* @category File
* @package File_ANSI
* @package ANSI
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib\File;
/**
* Pure-PHP ANSI Decoder
*
* @package File_ANSI
* @package ANSI
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class File_ANSI
class ANSI
{
/**
* Max Width
@ -190,7 +192,7 @@ class File_ANSI
/**
* Default Constructor.
*
* @return File_ANSI
* @return \phpseclib\File\ANSI
* @access public
*/
function __construct()

View File

@ -9,35 +9,31 @@
* utilized scheme is DER or the "Distinguished Encoding Rules". PEM's are base64 encoded
* DER blobs.
*
* File_ASN1 decodes and encodes DER formatted messages and places them in a semantic context.
* \phpseclib\File\ASN1 decodes and encodes DER formatted messages and places them in a semantic context.
*
* Uses the 1988 ASN.1 syntax.
*
* @category File
* @package File_ASN1
* @package ASN1
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
use \phpseclib\Math\BigInteger;
namespace phpseclib\File;
/**
* Include File_ASN1_Element
*/
if (!class_exists('File_ASN1_Element')) {
include_once 'ASN1/Element.php';
}
use phpseclib\File\ASN1\Element;
use phpseclib\Math\BigInteger;
/**
* Pure-PHP ASN.1 Parser
*
* @package File_ASN1
* @package ASN1
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class File_ASN1
class ASN1
{
/**#@+
* Tag Classes
@ -128,8 +124,8 @@ class File_ASN1
*
* @var Array
* @access private
* @see File_ASN1::setTimeFormat()
* @see File_ASN1::asn1map()
* @see \phpseclib\File\ASN1::setTimeFormat()
* @see \phpseclib\File\ASN1::asn1map()
* @link http://php.net/class.datetime
*/
var $encoded;
@ -141,14 +137,14 @@ class File_ASN1
*
* @var Array
* @access private
* @see File_ASN1::_encode_der()
* @see \phpseclib\File\ASN1::_encode_der()
*/
var $filters;
/**
* Type mapping table for the ANY type.
*
* Structured or unknown types are mapped to a File_ASN1_Element.
* Structured or unknown types are mapped to a \phpseclib\File\ASN1\Element.
* Unambiguous types get the direct mapping (int/real/bool).
* Others are mapped as a choice, with an extra indexing level.
*
@ -484,7 +480,7 @@ class File_ASN1
case $mapping['type'] == self::TYPE_ANY:
$intype = $decoded['type'];
if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || ($this->encoded[$decoded['start']] & 0x20)) {
return new File_ASN1_Element(substr($this->encoded, $decoded['start'], $decoded['length']));
return new Element(substr($this->encoded, $decoded['start'], $decoded['length']));
}
$inmap = $this->ANYmap[$intype];
if (is_string($inmap)) {
@ -1166,7 +1162,7 @@ class File_ASN1
/**
* Load filters
*
* See File_X509, etc, for an example.
* See \phpseclib\File\X509, etc, for an example.
*
* @access public
* @param Array $filters

View File

@ -5,23 +5,25 @@
* PHP versions 4 and 5
*
* @category File
* @package File_ASN1
* @package ASN1
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib\File\ASN1;
/**
* ASN.1 Element
*
* Bypass normal encoding rules in File_ASN1::encodeDER()
* Bypass normal encoding rules in phpseclib\File\ASN1::encodeDER()
*
* @package File_ASN1
* @package ASN1
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class File_ASN1_Element
class Element
{
/**
* Raw element value
@ -35,7 +37,7 @@ class File_ASN1_Element
* Constructor
*
* @param String $encoded
* @return File_ASN1_Element
* @return \phpseclib\File\ASN1\Element
* @access public
*/
function __construct($encoded)

File diff suppressed because it is too large Load Diff

View File

@ -5,59 +5,59 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'File/ASN1.php';
use phpseclib\File\ASN1;
class Unit_File_ASN1Test extends PhpseclibTestCase
{
/**
* on older versions of File_ASN1 this would yield a PHP Warning
* on older versions of \phpseclib\File\ASN1 this would yield a PHP Warning
* @group github275
*/
public function testAnyString()
{
$KDC_REP = array(
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => array(
'pvno' => array(
'constant' => 0,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'msg-type' => array(
'constant' => 1,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'padata' => array(
'constant' => 2,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'crealm' => array(
'constant' => 3,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'cname' => array(
'constant' => 4,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'ticket' => array(
'constant' => 5,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY),
'type' => ASN1::TYPE_ANY),
'enc-part' => array(
'constant' => 6,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY)
'type' => ASN1::TYPE_ANY)
)
);
$AS_REP = array(
'class' => File_ASN1::CLASS_APPLICATION,
'class' => ASN1::CLASS_APPLICATION,
'cast' => 11,
'optional' => true,
'explicit' => true
@ -75,7 +75,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
'4P3wep6uNMLnLzXJmUaAMaopjE+MOcai/t6T9Vg4pERF5Waqwg5ibAbVGK19HuS4LiKiaY3JsyYBuNkEDwiqM7i1Ekw3V+' .
'+zoEIxqgXjGgPdrWkzU/H6rnXiqMtiZZqUXwWY0zkCmy';
$asn1 = new File_ASN1();
$asn1 = new ASN1();
$decoded = $asn1->decodeBER(base64_decode($str));
$result = $asn1->asn1map($decoded[0], $AS_REP);
@ -83,37 +83,37 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
}
/**
* on older versions of File_ASN1 this would produce a null instead of an array
* on older versions of \phpseclib\File\ASN1 this would produce a null instead of an array
* @group github275
*/
public function testIncorrectString()
{
$PA_DATA = array(
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => array(
'padata-type' => array(
'constant' => 1,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_INTEGER
'type' => ASN1::TYPE_INTEGER
),
'padata-value' => array(
'constant' => 2,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_OCTET_STRING
'type' => ASN1::TYPE_OCTET_STRING
)
)
);
$PrincipalName = array(
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => array(
'name-type' => array(
'constant' => 0,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_INTEGER
'type' => ASN1::TYPE_INTEGER
),
'name-string' => array(
'constant' => 1,
@ -121,95 +121,95 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
'explicit' => true,
'min' => 0,
'max' => -1,
'type' => File_ASN1::TYPE_SEQUENCE,
'children' => array('type' => File_ASN1::TYPE_IA5_STRING) // should be File_ASN1::TYPE_GENERAL_STRING
'type' => ASN1::TYPE_SEQUENCE,
'children' => array('type' => ASN1::TYPE_IA5_STRING) // should be \phpseclib\File\ASN1::TYPE_GENERAL_STRING
)
)
);
$Ticket = array(
'class' => File_ASN1::CLASS_APPLICATION,
'class' => ASN1::CLASS_APPLICATION,
'cast' => 1,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => array(
'tkt-vno' => array(
'constant' => 0,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_INTEGER
'type' => ASN1::TYPE_INTEGER
),
'realm' => array(
'constant' => 1,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY
'type' => ASN1::TYPE_ANY
),
'sname' => array(
'constant' => 2,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY
'type' => ASN1::TYPE_ANY
),
'enc-part' => array(
'constant' => 3,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY
'type' => ASN1::TYPE_ANY
)
)
);
$KDC_REP = array(
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => array(
'pvno' => array(
'constant' => 0,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_INTEGER),
'type' => ASN1::TYPE_INTEGER),
'msg-type' => array(
'constant' => 1,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_INTEGER),
'type' => ASN1::TYPE_INTEGER),
'padata' => array(
'constant' => 2,
'optional' => true,
'explicit' => true,
'min' => 0,
'max' => -1,
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => $PA_DATA),
'crealm' => array(
'constant' => 3,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_OCTET_STRING),
'type' => ASN1::TYPE_OCTET_STRING),
'cname' => array(
'constant' => 4,
'optional' => true,
'explicit' => true) + $PrincipalName,
//'type' => File_ASN1::TYPE_ANY),
//'type' => ASN1::TYPE_ANY),
'ticket' => array(
'constant' => 5,
'optional' => true,
'implicit' => true,
'min' => 0,
'max' => 1,
'type' => File_ASN1::TYPE_SEQUENCE,
'type' => ASN1::TYPE_SEQUENCE,
'children' => $Ticket),
'enc-part' => array(
'constant' => 6,
'optional' => true,
'explicit' => true,
'type' => File_ASN1::TYPE_ANY)
'type' => ASN1::TYPE_ANY)
)
);
$AS_REP = array(
'class' => File_ASN1::CLASS_APPLICATION,
'class' => ASN1::CLASS_APPLICATION,
'cast' => 11,
'optional' => true,
'explicit' => true
@ -227,7 +227,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
'4P3wep6uNMLnLzXJmUaAMaopjE+MOcai/t6T9Vg4pERF5Waqwg5ibAbVGK19HuS4LiKiaY3JsyYBuNkEDwiqM7i1Ekw3V+' .
'+zoEIxqgXjGgPdrWkzU/H6rnXiqMtiZZqUXwWY0zkCmy';
$asn1 = new File_ASN1();
$asn1 = new ASN1();
$decoded = $asn1->decodeBER(base64_decode($str));
$result = $asn1->asn1map($decoded[0], $AS_REP);
@ -235,11 +235,11 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
}
/**
* older versions of File_ASN1 didn't handle indefinite length tags very well
* older versions of ASN1 didn't handle indefinite length tags very well
*/
public function testIndefiniteLength()
{
$asn1 = new File_ASN1();
$asn1 = new ASN1();
$decoded = $asn1->decodeBER(file_get_contents(dirname(__FILE__) . '/ASN1/FE.pdf.p7m'));
$this->assertCount(5, $decoded[0]['content'][1]['content'][0]['content']); // older versions would have returned 3
}
@ -264,7 +264,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
'AAOBgQAhrNWuyjSJWsKrUtKyNGadeqvu5nzVfsJcKLt0AMkQH0IT/GmKHiSgAgDp' .
'ulvKGQSy068Bsn5fFNum21K5mvMSf3yinDtvmX3qUA12IxL/92ZzKbeVCq3Yi7Le' .
'IOkKcGQRCMha8X2e7GmlpdWC1ycenlbN0nbVeSv3JUMcafC4+Q==';
$asn1 = new File_ASN1();
$asn1 = new ASN1();
$decoded = $asn1->decodeBER(base64_decode($str));
$this->assertCount(3, $decoded[0]['content']);
}
@ -274,7 +274,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
*/
public function testContextSpecificNonConstructed()
{
$asn1 = new File_ASN1();
$asn1 = new ASN1();
$decoded = $asn1->decodeBER(base64_decode('MBaAFJtUo7c00HsI5EPZ4bkICfkOY2Pv'));
$this->assertInternalType('string', $decoded[0]['content'][0]['content']);
}

View File

@ -5,7 +5,8 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'File/X509.php';
use phpseclib\File\X509;
require_once 'Crypt/RSA.php';
class Unit_File_X509_SPKACTest extends PhpseclibTestCase
@ -24,7 +25,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
'dmeL7aWrpP+3x3L0A9cATksracQX676XogdAEXJ59fcr/S5AGw1TFErbyBbfyeAWvzDZIXeMXpb9h' .
'yNtA==';
$x509 = new File_X509();
$x509 = new X509();
$spkac = $x509->loadSPKAC($test);
@ -50,7 +51,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
extract($privKey->createKey());
$privKey->loadKey($privatekey);
$x509 = new File_X509();
$x509 = new X509();
$x509->setPrivateKey($privKey);
$x509->setChallenge('...');
@ -59,7 +60,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
$this->assertInternalType('string', $x509->saveSPKAC($spkac));
$x509 = new File_X509();
$x509 = new X509();
$x509->setPrivateKey($privKey);
$spkac = $x509->signSPKAC();
@ -82,7 +83,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
'dmeL7aWrpP+3x3L0A9cATksracQX676XogdAEXJ59fcr/S5AGw1TFErbyBbfyeAWvzDZIXeMXpb9h' .
'yNtA==';
$x509 = new File_X509();
$x509 = new X509();
$spkac = $x509->loadSPKAC($test);