Skip to content
This repository was archived by the owner on Apr 23, 2023. It is now read-only.

Commit 889ef57

Browse files
committed
rename FG\ASN1\Object to FG\ASN1\ASNObject
Unfortunately PHP people decided its a good idea to make 'Object' a special class name in the upcomming PHP release. With this BC break we are now forced to start a new major version of PHPASN1.
1 parent 1e8a9b8 commit 889ef57

34 files changed

+115
-108
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### v.2.0.0 (2017-08)
2+
* rename `FG\ASN1\Object` to `FG\ASN1\ASNObject` because `Object` is a special class name in the next major PHP release
3+
- when you upgrade you have to adapt all corresponding `use` and `extends` statements as well as type hints and all
4+
usages of `Object::fromBinary(…)`.
5+
16
#### v.1.5.2 (2016-10-29)
27
* allow empty octet strings
38

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ echo base64_encode($myBinary);
7979
Decoding BER encoded binary data is just as easy as encoding it:
8080

8181
```php
82-
use FG\ASN1\Object;
82+
use FG\ASN1\ASNObject;
8383

8484
$base64String = ...
8585
$binaryData = base64_decode($base64String);
86-
$asnObject = Object::fromBinary($binaryData);
86+
$asnObject = ASNObject::fromBinary($binaryData);
87+
88+
8789
// do stuff
8890
```
8991

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"extra": {
4343
"branch-alias": {
44-
"dev-master": "1.5.x-dev"
44+
"dev-master": "2.0.x-dev"
4545
}
4646
}
4747
}

examples/Issue14.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once 'shared.php';
1313

1414
use FG\ASN1\OID;
15-
use FG\ASN1\Object;
15+
use FG\ASN1\ASNObject;
1616
use FG\ASN1\Identifier;
1717
use FG\ASN1\Universal\ObjectIdentifier;
1818
use FG\ASN1\Universal\OctetString;
@@ -67,7 +67,7 @@
6767
$binaryData = base64_decode($base64);
6868
//hexdump($binaryData, false);
6969

70-
$rootObject = Object::fromBinary($binaryData);
70+
$rootObject = ASNObject::fromBinary($binaryData);
7171
//printObject($rootObject);
7272

7373
// first navigate to the certificate extensions
@@ -86,7 +86,7 @@
8686
$certExtensions = $certInfoFields[7];
8787

8888
// check if this is really the certificate extensions sequence
89-
/* @var \FG\ASN1\Object $certExtensions */
89+
/* @var \FG\ASN1\ASNObject $certExtensions */
9090
$certExtensionsType = $certExtensions->getType();
9191
assert(Identifier::isContextSpecificClass($certExtensionsType));
9292
assert(Identifier::getTagNumber($certExtensions->getType()) == 3);
@@ -96,7 +96,7 @@
9696
assert($certExtensions->getType() == Identifier::SEQUENCE);
9797

9898
// now check all extensions and search for the SAN
99-
/** @var \FG\ASN1\Object $extensionSequence */
99+
/** @var \FG\ASN1\ASNObject $extensionSequence */
100100
foreach ($certExtensions as $extensionSequence) {
101101
assert($extensionSequence->getType() == Identifier::SEQUENCE);
102102
assert($extensionSequence->getNumberofChildren() >= 2);

examples/Issue29.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
use FG\ASN1\Object;
11+
use FG\ASN1\ASNObject;
1212

1313
require_once __DIR__.'/../vendor/autoload.php';
1414
require_once 'shared.php';
1515

1616
$hex = 'a02b302906092a864886f70d01090e311c301a30180603551d110411300f820d636f72766573706163652e6465';
17-
$asn = Object::fromBinary(hex2bin($hex));
17+
$asn = ASNObject::fromBinary(hex2bin($hex));
1818

1919
printObject($asn);

examples/Issue57.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
use FG\ASN1\ExplicitlyTaggedObject;
12-
use FG\ASN1\Object;
12+
use FG\ASN1\ASNObject;
1313
use FG\ASN1\Universal\Enumerated;
1414
use FG\ASN1\Universal\ObjectIdentifier;
1515
use FG\ASN1\Universal\Sequence;
@@ -84,7 +84,7 @@
8484

8585
try {
8686
echo 'Input 1:' . PHP_EOL;
87-
printObject(Object::fromBinary(base64_decode($input1)));
87+
printObject(ASNObject::fromBinary(base64_decode($input1)));
8888
} catch (Exception $exception) {
8989
echo "ERROR: " . $exception->getMessage();
9090
}
@@ -93,7 +93,7 @@
9393

9494
try {
9595
echo 'Input 2:' . PHP_EOL;
96-
printObject(Object::fromBinary(base64_decode($input2)));
96+
printObject(ASNObject::fromBinary(base64_decode($input2)));
9797
} catch (Exception $exception) {
9898
echo "ERROR: " . $exception->getMessage();
9999
}
@@ -102,7 +102,7 @@
102102

103103
try {
104104
echo 'Input 3:' . PHP_EOL;
105-
printObject(Object::fromBinary(base64_decode($input3)));
105+
printObject(ASNObject::fromBinary(base64_decode($input3)));
106106
} catch (Exception $exception) {
107107
echo "ERROR: " . $exception->getMessage();
108108
}

examples/allClasses.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once __DIR__.'/../vendor/autoload.php';
1313

1414
use FG\ASN1\OID;
15-
use FG\ASN1\Object;
15+
use FG\ASN1\ASNObject;
1616
use FG\ASN1\Universal\Boolean;
1717
use FG\ASN1\Universal\Integer;
1818
use FG\ASN1\Universal\Enumerated;
@@ -44,7 +44,7 @@
4444
$openSSLisAvailable = false;
4545
}
4646

47-
function printVariableInfo(Object $variable)
47+
function printVariableInfo(ASNObject $variable)
4848
{
4949
$className = get_class($variable);
5050
$stringValue = nl2br($variable->__toString());

examples/parseBinary.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require_once __DIR__.'/../vendor/autoload.php';
1212
require_once 'shared.php';
1313

14-
use FG\ASN1\Object;
14+
use FG\ASN1\ASNObject;
1515

1616
$base64String =
1717
'MIIFGDCCAwACAQAwOjEWMBQGCgmSJomT8ixkARkWBnNlY3VyZTEgMB4GA1UEAxMX
@@ -44,7 +44,7 @@
4444
draiRBZruwMPwPIP';
4545

4646
$binaryData = base64_decode($base64String);
47-
$asnObject = Object::fromBinary($binaryData);
47+
$asnObject = ASNObject::fromBinary($binaryData);
4848

4949
?>
5050

examples/shared.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
use FG\ASN1\Identifier;
4-
use FG\ASN1\Object;
4+
use FG\ASN1\ASNObject;
55

6-
function printObject(Object $object, $depth = 0)
6+
function printObject(ASNObject $object, $depth = 0)
77
{
88
$treeSymbol = '';
99
$depthString = str_repeat('', $depth);

lib/ASN1/Object.php renamed to lib/ASN1/ASNObject.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
use LogicException;
3939

4040
/**
41-
* Class Object is the base class for all concrete ASN.1 objects.
41+
* Class ASNObject is the base class for all concrete ASN.1 objects.
4242
*/
43-
abstract class Object implements Parsable
43+
abstract class ASNObject implements Parsable
4444
{
4545
private $contentLength;
4646
private $nrOfLengthOctets;
@@ -93,7 +93,7 @@ public function getIdentifier()
9393
$firstOctet = $this->getType();
9494

9595
if (Identifier::isLongForm($firstOctet)) {
96-
throw new LogicException(sprintf('Identifier of %s uses the long form and must therefor override "Object::getIdentifier()".', get_class($this)));
96+
throw new LogicException(sprintf('Identifier of %s uses the long form and must therefor override "ASNObject::getIdentifier()".', get_class($this)));
9797
}
9898

9999
return chr($firstOctet);
@@ -198,7 +198,7 @@ public function getTypeName()
198198
*
199199
* @throws ParserException
200200
*
201-
* @return \FG\ASN1\Object
201+
* @return \FG\ASN1\ASNObject
202202
*/
203203
public static function fromBinary(&$binaryData, &$offsetIndex = 0)
204204
{

lib/ASN1/AbstractString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use Exception;
1414

15-
abstract class AbstractString extends Object implements Parsable
15+
abstract class AbstractString extends ASNObject implements Parsable
1616
{
1717
/** @var string */
1818
protected $value;

lib/ASN1/AbstractTime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use DateTimeZone;
1616
use Exception;
1717

18-
abstract class AbstractTime extends Object
18+
abstract class AbstractTime extends ASNObject
1919
{
2020
/** @var DateTime */
2121
protected $value;

lib/ASN1/Composite/AttributeTypeAndValue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
namespace FG\ASN1\Composite;
1212

13-
use FG\ASN1\Object;
13+
use FG\ASN1\ASNObject;
1414
use FG\ASN1\Universal\Sequence;
1515
use FG\ASN1\Universal\ObjectIdentifier;
1616

1717
class AttributeTypeAndValue extends Sequence
1818
{
1919
/**
2020
* @param ObjectIdentifier|string $objIdentifier
21-
* @param \FG\ASN1\Object $value
21+
* @param \FG\ASN1\ASNObject $value
2222
*/
23-
public function __construct($objIdentifier, Object $value)
23+
public function __construct($objIdentifier, ASNObject $value)
2424
{
2525
if ($objIdentifier instanceof ObjectIdentifier == false) {
2626
$objIdentifier = new ObjectIdentifier($objIdentifier);

lib/ASN1/Composite/RDNString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RDNString extends RelativeDistinguishedName
1818
{
1919
/**
2020
* @param string|\FG\ASN1\Universal\ObjectIdentifier $objectIdentifierString
21-
* @param string|\FG\ASN1\Object $value
21+
* @param string|\FG\ASN1\ASNObject $value
2222
*/
2323
public function __construct($objectIdentifierString, $value)
2424
{

lib/ASN1/Composite/RelativeDistinguishedName.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
namespace FG\ASN1\Composite;
1212

1313
use FG\ASN1\Exception\NotImplementedException;
14-
use FG\ASN1\Object;
14+
use FG\ASN1\ASNObject;
1515
use FG\ASN1\Universal\Set;
1616

1717
class RelativeDistinguishedName extends Set
1818
{
1919
/**
2020
* @param string|\FG\ASN1\Universal\ObjectIdentifier $objIdentifierString
21-
* @param \FG\ASN1\Object $value
21+
* @param \FG\ASN1\ASNObject $value
2222
*/
23-
public function __construct($objIdentifierString, Object $value)
23+
public function __construct($objIdentifierString, ASNObject $value)
2424
{
2525
// TODO: This does only support one element in the RelativeDistinguishedName Set but it it is defined as follows:
2626
// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue
@@ -29,7 +29,7 @@ public function __construct($objIdentifierString, Object $value)
2929

3030
public function getContent()
3131
{
32-
/** @var \FG\ASN1\Object $firstObject */
32+
/** @var \FG\ASN1\ASNObject $firstObject */
3333
$firstObject = $this->children[0];
3434
return $firstObject->__toString();
3535
}

lib/ASN1/Construct.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Countable;
1616
use Iterator;
1717

18-
abstract class Construct extends Object implements Countable, ArrayAccess, Iterator, Parsable
18+
abstract class Construct extends ASNObject implements Countable, ArrayAccess, Iterator, Parsable
1919
{
20-
/** @var \FG\ASN1\Object[] */
20+
/** @var \FG\ASN1\ASNObject[] */
2121
protected $children;
2222
private $iteratorPosition;
2323

2424
/**
25-
* @param \FG\ASN1\Object[] $children the variadic type hint is commented due to https://github.com/facebook/hhvm/issues/4858
25+
* @param \FG\ASN1\ASNObject[] $children the variadic type hint is commented due to https://github.com/facebook/hhvm/issues/4858
2626
*/
2727
public function __construct(/* HH_FIXME[4858]: variadic + strict */ ...$children)
2828
{
@@ -104,7 +104,7 @@ protected function getEncodedValue()
104104
return $result;
105105
}
106106

107-
public function addChild(Object $child)
107+
public function addChild(ASNObject $child)
108108
{
109109
$this->children[] = $child;
110110
}
@@ -130,15 +130,15 @@ public function getNumberOfChildren()
130130
}
131131

132132
/**
133-
* @return \FG\ASN1\Object[]
133+
* @return \FG\ASN1\ASNObject[]
134134
*/
135135
public function getChildren()
136136
{
137137
return $this->children;
138138
}
139139

140140
/**
141-
* @return \FG\ASN1\Object
141+
* @return \FG\ASN1\ASNObject
142142
*/
143143
public function getFirstChild()
144144
{
@@ -162,7 +162,7 @@ public static function fromBinary(&$binaryData, &$offsetIndex = 0)
162162
$children = [];
163163
$octetsToRead = $contentLength;
164164
while ($octetsToRead > 0) {
165-
$newChild = Object::fromBinary($binaryData, $offsetIndex);
165+
$newChild = ASNObject::fromBinary($binaryData, $offsetIndex);
166166
$octetsToRead -= $newChild->getObjectLength();
167167
$children[] = $newChild;
168168
}

lib/ASN1/ExplicitlyTaggedObject.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
*
3030
* @see http://luca.ntop.org/Teaching/Appunti/asn1.html
3131
*/
32-
class ExplicitlyTaggedObject extends Object
32+
class ExplicitlyTaggedObject extends ASNObject
3333
{
34-
/** @var \FG\ASN1\Object[] */
34+
/** @var \FG\ASN1\ASNObject[] */
3535
private $decoratedObjects;
3636
private $tag;
3737

3838
/**
3939
* @param int $tag
40-
* @param \FG\ASN1\Object $objects,...
40+
* @param \FG\ASN1\ASNObject $objects,...
4141
*/
4242
public function __construct($tag, /* HH_FIXME[4858]: variadic + strict */ ...$objects)
4343
{
@@ -115,7 +115,7 @@ public static function fromBinary(&$binaryData, &$offsetIndex = 0)
115115
$decoratedObjects = [];
116116

117117
while ($remainingContentLength > 0) {
118-
$nextObject = Object::fromBinary($binaryData, $offsetIndex);
118+
$nextObject = ASNObject::fromBinary($binaryData, $offsetIndex);
119119
$remainingContentLength -= $nextObject->getObjectLength();
120120
$decoratedObjects[] = $nextObject;
121121
}

lib/ASN1/TemplateParser.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TemplateParser
1919
/**
2020
* @param string $data
2121
* @param array $template
22-
* @return \FG\ASN1\Object|Sequence
22+
* @return \FG\ASN1\ASNObject|Sequence
2323
* @throws ParserException if there was an issue parsing
2424
*/
2525
public function parseBase64($data, array $template)
@@ -31,12 +31,12 @@ public function parseBase64($data, array $template)
3131
/**
3232
* @param string $binary
3333
* @param array $template
34-
* @return \FG\ASN1\Object|Sequence
34+
* @return \FG\ASN1\ASNObject|Sequence
3535
* @throws ParserException if there was an issue parsing
3636
*/
3737
public function parseBinary($binary, array $template)
3838
{
39-
$parsedObject = Object::fromBinary($binary);
39+
$parsedObject = ASNObject::fromBinary($binary);
4040

4141
foreach ($template as $key => $value) {
4242
$this->validate($parsedObject, $key, $value);
@@ -45,7 +45,7 @@ public function parseBinary($binary, array $template)
4545
return $parsedObject;
4646
}
4747

48-
private function validate(Object $object, $key, $value)
48+
private function validate(ASNObject $object, $key, $value)
4949
{
5050
if (is_array($value)) {
5151
$this->assertTypeId($key, $object);
@@ -60,7 +60,7 @@ private function validate(Object $object, $key, $value)
6060
}
6161
}
6262

63-
private function assertTypeId($expectedTypeId, Object $object)
63+
private function assertTypeId($expectedTypeId, ASNObject $object)
6464
{
6565
$actualType = $object->getType();
6666
if ($expectedTypeId != $actualType) {

0 commit comments

Comments
 (0)