Skip to content

feat: new rust decoder #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 3, 2023
Merged

feat: new rust decoder #17

merged 14 commits into from
Mar 3, 2023

Conversation

bzp2010
Copy link
Contributor

@bzp2010 bzp2010 commented Mar 2, 2023

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.

@bzp2010 bzp2010 self-assigned this Mar 2, 2023
@bzp2010 bzp2010 marked this pull request as ready for review March 2, 2023 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants