kanidm / ldap3

Rust LDAP3 Server Protocol Library
Mozilla Public License 2.0
51 stars 11 forks source link

How to represent integer attributes? #27

Closed nitnelave closed 1 year ago

nitnelave commented 1 year ago

Let's say I want to create a LdapPartialAttribute with a numerical value.

LdapPartialAttribute {
  atype: "uid".to_owned(),
  vals: vec![123],
}

How do I represent that 123 as bytes? Is there a special encoding necessary? Or do I convert it to i64 then do a cast to 8 raw bytes?

Firstyear commented 1 year ago

There are two options: https://www.rfc-editor.org/rfc/rfc4517#section-3.3.16 You can make it a integer here which is the output of i64 to_string() and then parsed.

Or you can use https://www.rfc-editor.org/rfc/rfc4517#section-3.3.25 and convert to a byte-array stored as an octet string, and then back again.

Generally if this was a uidNumber such as in posix, you would use the former integer-string method.

nitnelave commented 1 year ago

I'm looking to be as compatible as possible with common ldap tools, like ldapsearch. Would it make sense to add a int-to-byte-array conversion function in this repo? It would facilitate clients' life, I guess. Or is the "compatible" option the string representation?

Firstyear commented 1 year ago

compatible is the string representation from my experience.

nitnelave commented 1 year ago

Perfect, thanks.