api7 / lua-resty-ldap

Apache License 2.0
5 stars 6 forks source link

feat: new rust decoder #17

Closed bzp2010 closed 1 year ago

bzp2010 commented 1 year ago

The current ASN.1 codec in the library uses the OpenSSL function imported via LuaJIT FFI, which is very primitive and has usability issues (for example, it does not properly parse the ASN.1 format returned by Active Directory, and the four extra bytes used to represent the length of the data cannot be handled).

This PR introduces a Lua extension implemented in Rust, which provides a codec for data encoding and decoding. This part is decoupled from OpenResty and depends only on LuaVM (in this case LuaJIT), which only handles data encoding and decoding while data sending and receiving is implemented by cosocket.

It uses a series of Rust libraries, mlua, rasn, etc. The mlua is used to implement the LuaVM bridge which uses the lua.h header file to import functions instead of statically compiling them (fortunately the LuaJIT branch used by the mlua library maintainer is the same one used by openresty). And rasn and its dependant package rasn-ldap is an ASN.1 specification codec, and I mainly use its DER decoding part.

Therefore the introduced component is actually a glue layer implementation of ASN.1 and LuaVM, provide the conversion of ASN.1 byte streams and Lua tables.

This library will be compiled and loaded as a so file, the original size is about 4MB, the size of the so file after srip is about 640~KB. it can be further compressed if needed, like no_std or something like that.