A while ago, I wrote an LDAP server. Well, nothing as complex as OpenLDAP; just a simple LDAP protocol parser which could translate LDAP requests into requests to modify an internal in-memory data representation of the LDAP database. I actually managed to make it work against a product we were working on at the time.
Part of the problem with that code is that I used the BER ASN.1 library that was part of the Netscape LDAP API library, which while rather interesting, was rather weak in that it was written to be just good enough to deal with the LDAP client spec–and no better. (In fact I had to kludge the hell out of my code to make the LDAP server spec work, as the LDAP server spec is heavy on using the [APPLICATION] tag for just about everything. Turns out there is an ambiguity that had to be dealt with using some odd special-case code.)
So I wrote a replacement library, rewrote my LDAP code to use the new library, and away I went. Someday I’ll post the full LDAP engine, but in the meantime, I finally got around to both documenting my ASN.1 BER parser engine on the Wiki, and uploading the source kit. You can visit the main ASN.1 web page here, or go to the wiki for more information.