LDAP Distinguished Name (DN) Parser
This Rust crate parses Lightweight Directory Access Protocol (LDAP) Distinguished Names (DNs) according to the syntax in IETF RFC 4514. It does no heap allocations or copies of strings, so it should be Blazing Fast(tm), although this has not been tested against other implementations. It also does not require the standard library or any dependencies.
This crate has been fuzz-tested. It checks for an odd number of trailing slashes in attribute values to prevent injection attacks.
Usage
You can parse LDAP distinguished names like so:
use dn_from_str;
let s = "gn=Jonathan+sn=Wilbur,st=FL,c=US";
let dn_iter = dn_from_str;
let mut atav_count = 0;
for rdn in dn_iter
assert_eq!;
The attribute values returned a NOT ESCAPED. You will have to do this as a separate step, if you believe you need it.
You can unescape LDAP attribute values using one of these four functions:
unescape_ldap_value_inplace- Unescape a mutable byte slice in placeunescape_ldap_value_string- Unescape a mutable string in placeunescape_ldap_value_cow- Unescape a mutable byte slice, returning a clone if unescaping occurredunescape_ldap_value_string_cow- Unescape a mutable string, returning a clone if unescaping occurred
Here is an example of usage:
extern crate alloc;
use Vec;
use String;
use ;
let mut bytes = Vecfrom;
let result = unescape_ldap_value_inplace;
assert_eq!;
let mut s = Stringfrom;
let unescaped = unescape_ldap_value_string_cow.expect;
let new_s = unescaped.as_ref;
assert_eq!;
no_std Usage
This crate can function without a standard library (no_std).
The lone feature flag alloc is enabled by default, and it turns on
unescape_ldap_value_cow and unescape_ldap_value_string_cow,
which are useful if it is inconvenient to obtain a mutable reference to an
attribute value string.
AI Usage Statement
None of the code for parsing distinguished names was produced by an AI or LLM of any kind. The code for unescaping attribute values used in distinguished names was initially written by AI / LLM, but were then heavily modified. The unit tests were written by AI / LLM, but verified by the author of this crate.