Skip to content

Commit aa15fb8

Browse files
authored
Merge pull request #8 from bashkarev/fix-eoc
getDecoratedObject does not enforce proper use of end-of-content (EOC) markers
2 parents b0ea781 + 3629747 commit aa15fb8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ASN1/AbstractTaggedObject.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public function getDecoratedObject($tagNumber, $tagClass = Identifier::CLASS_UNI
1212
$identifierOctets = IdentifierManager::create($tagClass, $isConstructed, $tagNumber);
1313

1414
$binary = $identifierOctets.$this->getContentLength()->getBinary().$this->getContent()->getBinary();
15+
if ($this->eoc) {
16+
$binary .= $this->eoc->getBinary();
17+
}
1518

1619
return ASN1Object::fromBinary($binary);
1720
}

tests/ASN1/ExplicitlyTaggedObjectTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,24 @@ public function testFromBinaryWithMultipleObjects()
107107
$this->assertEquals(2+$length, $object->getObjectLength());
108108
$this->assertEquals($data, $object->getBinary());
109109
}
110+
111+
public function testDecorated()
112+
{
113+
$object1 = Boolean::create(true);
114+
$object2 = Integer::create(42);
115+
$identifier = 0xA0;
116+
117+
// SHORT_FORM
118+
$length = $object1->getObjectLength() + $object2->getObjectLength();
119+
$data = chr($identifier) . chr($length) . $object1->getBinary() . $object2->getBinary();
120+
$object = ExplicitlyTaggedObject::fromBinary($data);
121+
$decoratedData = $object->getDecoratedObject(0, Identifier::CLASS_CONTEXT_SPECIFIC, true)->getBinary();
122+
$this->assertEquals($data, $decoratedData);
123+
124+
// INDEFINITE_FORM
125+
$dataEoc = chr($identifier) . chr(128) . $object1->getBinary() . $object2->getBinary() . chr(0) . chr(0);
126+
$object = ExplicitlyTaggedObject::fromBinary($dataEoc);
127+
$decoratedData = $object->getDecoratedObject(0, Identifier::CLASS_CONTEXT_SPECIFIC, true)->getBinary();
128+
$this->assertEquals($dataEoc, $decoratedData);
129+
}
110130
}

0 commit comments

Comments
 (0)