-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spacewander
approved these changes
Mar 2, 2023
kingluo
approved these changes
Mar 2, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. Themlua
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.