lib/ldap: Fix LdapConnection::encodeSortRules()

refs #9364
This commit is contained in:
Eric Lippmann 2015-09-03 17:47:54 +02:00
parent 70a6157631
commit 00e5bbe91c

View File

@ -910,28 +910,29 @@ class LdapConnection implements Selectable, Inspectable
* *
* @param array $sortRules * @param array $sortRules
* *
* @return string * @return string Binary representation of the octet stream
* @throws ProgrammingError
*
* @todo Produces an invalid stream, obviously
*/ */
protected function encodeSortRules(array $sortRules) protected function encodeSortRules(array $sortRules)
{ {
if (count($sortRules) > 127) { // TODO(el): Indefinite form of length octet
throw new ProgrammingError( $sequenceOf = '';
'Cannot encode more than 127 sort rules. Only length octets in short form are supported'
);
}
$seq = '30' . str_pad(dechex(count($sortRules)), 2, '0', STR_PAD_LEFT);
foreach ($sortRules as $rule) { foreach ($sortRules as $rule) {
$hexdAttribute = unpack('H*', $rule[0]); $reversed = '0101' . ($rule[1] === Sortable::SORT_DESC ? 'ff' : '00');
$seq .= '3002'
. '04' . str_pad(dechex(strlen($rule[0])), 2, '0', STR_PAD_LEFT) . $hexdAttribute[1]
. '0101' . ($rule[1] === Sortable::SORT_DESC ? 'ff' : '00');
}
return $seq; $attributeType = unpack('H*', $rule[0]);
$attributeType = $attributeType[1];
$attributeType = '04' . str_pad(dechex(strlen($attributeType) / 2), 2, '0', STR_PAD_LEFT) . $attributeType;
$sequence = '30'
. str_pad(dechex(strlen($attributeType . $reversed) / 2), 2, '0', STR_PAD_LEFT)
. $attributeType
. $reversed;
$sequenceOf .= $sequence;
}
$sequenceOf = '30'
. str_pad(dechex(strlen($sequenceOf) / 2), 2, '0', STR_PAD_LEFT)
. $sequenceOf;
return hex2bin($sequenceOf);
} }
/** /**