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.
Referencing #61
We had discussed about whether our crate can support WASM. This PR creates a demonstration of the same.
Instructions to run
wasm-pack
installed. It can be found here. Simply runcargo install wasm-pack
. This is used to create the WASM files based on our target (which in this case is the web). It also has the potential to create WASM files for different targets as well such as NodeJS.wasm-pack build --target web
. It will create WASM binaries in./pkg/
.index.html
served by a simple Python server to avoid CORS issues. This can be done by runningpython -m http.server
in the same directory asindex.html
.Dissect Packet
button to see this:My Analysis
./pkg/scalpel.js
, created bywasm-pack
. I tried loading the./pkg/scalpel_bg.wasm
file directly into the script, however, I was facing some import issues. It turns out thatWebAssembly is not yet integrated with <script type='module'> or import statements, thus there is not a path to have the browser fetch modules for you using imports.
as stated in MDN Docs. Therefore, instead of tediously creating theArrayBuffer
s for containing the WASM binary and following a few more steps, I ended up using thewasm-pack
generated./pkg/scalpel.js
file. (However, the alternative options of loading and running the WASM binary directly can be explored)dissect_packet
function to thelib.rs
file temporarily.wasm-pack
generates WASM bindings for particular functions, that have the#[wasm_bindgen]
attribute. They can't be tested from examples. Therefore, we need to look into creating a separate module to provide the functions that can be used by the browser, or any other entity using the WASM file. The functions that can be supported are a point of discussionENCAP_TYPE_ETH
, however in the future functions that are to be written, this must be taken care of.More areas to look into
cargo test --target wasm32-unknown-unknown
Further Resources
wasm-bindgen
Guidewasm-pack