1<?php 2 3/** 4 * This file is part of the FreeDSx LDAP LDAP package. 5 * 6 * (c) Chad Sikorra <Chad.Sikorra@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace FreeDSx\Ldap\Protocol; 13 14use FreeDSx\Asn1\Encoder\BerEncoder; 15use FreeDSx\Asn1\Type\AbstractType; 16 17/** 18 * Applies some LDAP specific rules, and mappings, to the BER encoder, specified in RFC 4511. 19 * 20 * - Only the definite form of length encoding is used. 21 * - OCTET STRING values are encoded in the primitive form only. 22 * - If the value of a BOOLEAN type is true, the encoding of the value octet is set to hex "FF". 23 * - If a value of a type is its default value, it is absent. 24 * 25 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 26 */ 27class LdapEncoder extends BerEncoder 28{ 29 /** 30 * {@inheritdoc} 31 */ 32 public function __construct() 33 { 34 parent::__construct([ 35 'primitive_only' => [ 36 AbstractType::TAG_TYPE_OCTET_STRING, 37 ], 38 ]); 39 $this->setTagMap(AbstractType::TAG_CLASS_APPLICATION, [ 40 0 => AbstractType::TAG_TYPE_SEQUENCE, 41 1 => AbstractType::TAG_TYPE_SEQUENCE, 42 2 => AbstractType::TAG_TYPE_NULL, 43 3 => AbstractType::TAG_TYPE_SEQUENCE, 44 4 => AbstractType::TAG_TYPE_SEQUENCE, 45 5 => AbstractType::TAG_TYPE_SEQUENCE, 46 6 => AbstractType::TAG_TYPE_SEQUENCE, 47 7 => AbstractType::TAG_TYPE_SEQUENCE, 48 8 => AbstractType::TAG_TYPE_SEQUENCE, 49 9 => AbstractType::TAG_TYPE_SEQUENCE, 50 10 => AbstractType::TAG_TYPE_OCTET_STRING, 51 11 => AbstractType::TAG_TYPE_SEQUENCE, 52 12 => AbstractType::TAG_TYPE_SEQUENCE, 53 13 => AbstractType::TAG_TYPE_SEQUENCE, 54 14 => AbstractType::TAG_TYPE_SEQUENCE, 55 15 => AbstractType::TAG_TYPE_SEQUENCE, 56 16 => AbstractType::TAG_TYPE_INTEGER, 57 19 => AbstractType::TAG_TYPE_SEQUENCE, 58 23 => AbstractType::TAG_TYPE_SEQUENCE, 59 24 => AbstractType::TAG_TYPE_SEQUENCE, 60 25 => AbstractType::TAG_TYPE_SEQUENCE, 61 ]); 62 } 63} 64