diff --git a/Cargo.toml b/Cargo.toml index f434f6c..3bd1b71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ serde_json = { version = "1.0" } erased-serde = "0.4" pyo3 = { version = "0.20", features = ["extension-module"], optional=true} log = { version = "0.4", optional = true } +wasm-bindgen = "0.2.92" [dev-dependencies] criterion = "0.5" diff --git a/index.html b/index.html new file mode 100644 index 0000000..39fddd8 --- /dev/null +++ b/index.html @@ -0,0 +1,40 @@ + + + + + Scalpel using WASM + + + +

Scalpel using WASM

+

Byte Stream to be dissected

+

+ + +
+ + + + + diff --git a/src/lib.rs b/src/lib.rs index 81b373d..8817849 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,23 @@ pub use types::{ENCAP_TYPE_ETH, ENCAP_TYPE_LINUX_SLL, ENCAP_TYPE_LINUX_SLL2}; #[cfg(feature = "python-bindings")] use pyo3::prelude::*; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn dissect_packet(packet: String) -> String { + let _ = layers::register_defaults(); + + let packet = hex::decode(packet); + + let packet = packet.unwrap(); + + let p = Packet::from_bytes(&packet, ENCAP_TYPE_ETH); + + let p = p.unwrap(); + + serde_json::to_string_pretty(&p).unwrap() +} + /// Python bindings for packet dissection and sculpting in Rust (scalpel) #[cfg(feature = "python-bindings")] #[pymodule]