inejge / ldap3

A pure-Rust LDAP library using the Tokio stack
Apache License 2.0
220 stars 38 forks source link

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

Closed nitnelave closed 2 years ago

nitnelave commented 2 years ago

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>> ?

inejge commented 2 years ago

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.

nitnelave commented 2 years ago

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!