コード例 #1
0
ファイル: SequenceTest.php プロジェクト: afk11/phpasn1
 public function testGetBinary()
 {
     $child1 = new Boolean(true);
     $object = new Sequence($child1);
     $expectedType = chr(Identifier::SEQUENCE);
     $expectedLength = chr(0x3);
     $expectedContent = $child1->getBinary();
     $this->assertEquals($expectedType . $expectedLength . $expectedContent, $object->getBinary());
     $child1 = new Integer(123);
     $child2 = new Boolean(true);
     $object = new Sequence($child1, $child2);
     $expectedLength = chr(0x6);
     $expectedContent = $child1->getBinary();
     $expectedContent .= $child2->getBinary();
     $this->assertEquals($expectedType . $expectedLength . $expectedContent, $object->getBinary());
 }
コード例 #2
0
 public function testFromBinaryWithMultipleObjects()
 {
     $object1 = new Boolean(true);
     $object2 = new Integer(42);
     $identifier = 0xa0;
     $length = $object1->getObjectLength() + $object2->getObjectLength();
     $data = chr($identifier) . chr($length) . $object1->getBinary() . $object2->getBinary();
     $object = ExplicitlyTaggedObject::fromBinary($data);
     $this->assertEquals(2 + $length, $object->getObjectLength());
     $this->assertEquals([$object1, $object2], $object->getContent());
     $this->assertEquals($data, $object->getBinary());
     $this->assertEquals('2 context specific objects with tag [0]', $object->__toString());
 }