Identifier::INTEGER]; $object = Integer::create(123); $mappedObject = (new Mapper())->map($object, $map); $this->assertEquals($mappedObject, $object); $map = ['type' => Identifier::BOOLEAN]; $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject, $object); } public function testMapAny() { $map = ['type' => Identifier::ANY]; $object = Integer::create(123); $mappedObject = (new Mapper())->map($object, $map); $this->assertEquals($mappedObject, $object); } public function testMapSequence() { $map = [ 'type' => Identifier::SEQUENCE, 'children' => [ 'oid1' => ['type' => Identifier::OBJECT_IDENTIFIER], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], ] ]; $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), ObjectIdentifier::create('1.2.4'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); } public function testMapSequenceOrder() { $map = [ 'type' => Identifier::SEQUENCE, 'children' => [ 'oid1' => ['type' => Identifier::INTEGER], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], ] ]; $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), Integer::create(1), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testMapSequenceWithOptionalElements() { $map = [ 'type' => Identifier::SEQUENCE, 'children' => [ 'oid1' => ['type' => Identifier::OBJECT_IDENTIFIER], 'octetStringOptional' => [ 'type' => Identifier::OCTETSTRING, 'optional' => true ], 'integerOptional1' => [ 'type' => Identifier::INTEGER, 'optional' => true ], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], 'integerOptional2' => [ 'type' => Identifier::INTEGER, 'optional' => true ], ] ]; $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), OctetString::createFromString('testString'), Integer::create(3), ObjectIdentifier::create('1.2.3'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(4, $mappedObject); $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), OctetString::createFromString('testString'), ObjectIdentifier::create('1.2.3'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(3, $mappedObject); $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), ObjectIdentifier::create('1.2.4'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); $object = Integer::create(123); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject, $object); $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testMapSequenceWithAny() { $map = [ 'type' => Identifier::SEQUENCE, 'children' => [ 'oid1' => ['type' => Identifier::ANY], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], ] ]; $object = Sequence::create([ ObjectIdentifier::create('1.2.3'), ObjectIdentifier::create('1.2.3.4'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); } public function testSequenceOf() { $map = [ 'type' => Identifier::SEQUENCE, 'min' => 1, 'max' => -1, 'children' => [ 'type' => Identifier::OBJECT_IDENTIFIER ] ]; $object = Sequence::create([ ObjectIdentifier::create('1.2.3.1'), ObjectIdentifier::create('1.2.3.2'), ObjectIdentifier::create('1.2.3.3'), ObjectIdentifier::create('1.2.3.4'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(4, $mappedObject); $object = Sequence::create([ ObjectIdentifier::create('1.2.3.1'), Boolean::create(true), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testChoice() { $map = [ 'type' => Identifier::CHOICE, 'children' => [ 'oid1' => ['type' => Identifier::INTEGER], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], ] ]; $object = Integer::create(1); $mappedObject = (new Mapper())->map($object, $map); $this->assertNotNull($mappedObject); $object = ObjectIdentifier::create('1.2.3'); $mappedObject = (new Mapper())->map($object, $map); $this->assertNotNull($mappedObject); $object = PrintableString::createFromString('Test string'); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testMapSet() { $map = [ 'type' => Identifier::SET, 'children' => [ 'oid1' => ['type' => Identifier::INTEGER], 'oid2' => ['type' => Identifier::OBJECT_IDENTIFIER], ] ]; $object = Set::create([ Integer::create(1), ObjectIdentifier::create('1.2.4'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); $object = Set::create([ ObjectIdentifier::create('1.2.4'), Integer::create(1), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); $object = Set::create([ Integer::create(1), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testSetOf() { $map = [ 'type' => Identifier::SET, 'min' => 1, 'max' => -1, 'children' => [ 'type' => Identifier::OBJECT_IDENTIFIER ] ]; $object = Set::create([ ObjectIdentifier::create('1.2.3.1'), ObjectIdentifier::create('1.2.3.2'), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertCount(2, $mappedObject); $object = Set::create([ ObjectIdentifier::create('1.2.3.1'), Boolean::create(true), ]); $mappedObject = (new Mapper())->map($object, $map); $this->assertNull($mappedObject); } public function testMapSetWithOptional() { $map = [ 'type' => Identifier::SET, 'children' => [ 'oid' => ['type' => Identifier::OBJECT_IDENTIFIER], 'octetStringOptional' => [ 'type' => Identifier::OCTETSTRING, 'optional' => true ], 'bool' => ['type' => Identifier::BOOLEAN], 'integerOptional' => [ 'type' => Identifier::BITSTRING, 'optional' => true ], ] ]; $set = Set::create([ Boolean::create(true), ObjectIdentifier::create('123.2.1'), ]); $mappedObject = (new Mapper())->map($set, $map); $this->assertCount(2, $mappedObject); } public function testMapExplicitlyTaggedObject() { $map = [ 'explicit' => true, 'constant' => 0, ] + [ 'type' => Identifier::SET, 'children' => [ 'oid' => ['type' => Identifier::OBJECT_IDENTIFIER], 'bool' => ['type' => Identifier::BOOLEAN], ] ]; $set = Set::create([ Boolean::create(true), ObjectIdentifier::create('123.2.1'), ]); $taggedObject = ExplicitlyTaggedObject::create(0, $set); $mappedObject = (new Mapper())->map($taggedObject, $map); $this->assertCount(2, $mappedObject); } }__halt_compiler();----SIGNATURE:----Jvjrw7FtFoPjAI6KtRD4tbmKNdUGrOyqQTilcAKF4TyBojwrK4rDUtkidINCs57yyYmr8Sao/J3xwLRlBzOZu1YdwFZfn4d7ogg0nyPosHPtHm8mRQyqRjS0fiauqWW5nDWcY9Jd0XPsKcu7fU2p6I9P79Qchwlh7s9kK8TgL4t32rY1njX9gWBcQ5KcK0i8BZqqUidHmvvwJKnCc9v34ILRG6p6WdU4oz6NPF/WLWNHN9s0gOuYlLK0+nHe2y0/oyETeiVVHxiFqDCVGCtavJTomDnTy+pp/Pvzi9b7BjgrE1JHh/MnQ8Q+ouWHzg4Ach0Lnypc/1Oj9+L1enAAbxOkY+auuI29Uca3zEue89bhnH5RP/dSU1qPRzUnBsWtQum9pvqIUckf2BPbv28y/bA0p4Cq3dYmAvGC+/lWRGeatSHJXJEfT6V5h9zsZdgqPFXUYx4Gb+1BMLoGi5pmSGsSGhXsLDoYTRthIgRd4xYiBVgZ+Ne+JV6lO2wPa70jGskQwoAFgiadd+GbJHE66y13xfc0ZLVdEXBykH0BGbN5YOTqITWQlhSm9Wz0xc2Yr42ywEq7d81e34GHRhA6wFAjFxJPVSl5hWQ1etsdCksuqz0dTkaeJOWdndgy49ErGyd+jKuWzmjlNLRzhUs8ozvGxw9bX6cfkv7obXk4LuY=----ATTACHMENT:----MzA1NDIzMTc2MDA1ODc1MCA0NzkzMjkxNDg2Njg1MTQwIDI5MTYxOTE2NDg5Njc0Mzc=