inejge/ldap3

Attributes are resolved as `String`, but they're not always utf-8

nitnelave opened this issue · 2 comments

A somewhat common use of LDAP is to store the avatar picture, e.g. with jpegPhoto. It is stored as bytes, and not necessarily valid UTF-8, so it cannot be represented by a String.

Would it be possible to change the SearchEntry::attrs map to be to a Vec<Vec<u8>> ?

If a raw attribute value can't be converted to a String (while parsing the entry in SearchEntry::construct()), that attribute's values are placed in the bin_attrs map, whose values are Vec<Vec<u8>>. This is documented in the description of SearchEntry. If you retrieve an entry with an attribute you expect to be binary, check both attrs and bin_attrs on the off chance that the particular set of its values can be parsed as UTF-8.

Ouch, my bad, I didn't read the docs well enough... I had a bit of tunnel vision after solving the same issue in another crate.
I like your solution, it keeps the convenience most of the time and allows for better control!