From a67a32b3f6b785122a6753bfda8c6ed1818a2442 Mon Sep 17 00:00:00 2001 From: Mihail Kirov Date: Wed, 9 Aug 2023 10:58:02 +0200 Subject: [PATCH] chore: cargo fmt --- src/injecting/injections.rs | 5 ++--- src/injecting/injector.rs | 6 +++--- src/lib.rs | 11 +++++------ src/util.rs | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/injecting/injections.rs b/src/injecting/injections.rs index 8dde676..1fab69c 100644 --- a/src/injecting/injections.rs +++ b/src/injecting/injections.rs @@ -6,10 +6,10 @@ use wasm_instrument::parity_wasm::elements::{ use super::injector::FunctionMapper; /// # Injection enum -/// +/// /// This enum is used to select which injection to perform i.e what instructions to insert in the beginning of the WASM module. /// # Example -/// +/// /// ``` /// let mut module = load_module(); // you can use wasm_injector::util to load a module /// let injection = Injection::Noops; @@ -25,7 +25,6 @@ pub enum Injection { HeapOverflow, } - impl Injection { /// # Takes a module and injects the selected injection into the module. pub fn inject(self, module: &mut Module, function: &str) -> Result<(), String> { diff --git a/src/injecting/injector.rs b/src/injecting/injector.rs index ca69319..4195c1b 100644 --- a/src/injecting/injector.rs +++ b/src/injecting/injector.rs @@ -31,9 +31,9 @@ pub trait FunctionMapper { impl FunctionMapper for Module { /// # Takes a module and a function name and returns the global function index of the function. - /// + /// /// # Errors - /// + /// /// - Returns an error if the function is not found in the export section. /// - Returns an error if the u32 cannot be mapped to usize. fn get_global_function_index(&mut self, function_name: &str) -> Result { @@ -69,7 +69,7 @@ impl FunctionMapper for Module { } /// # Takes a module, a local function index and a function name and returns the function body. - /// + /// /// # Errors /// - Returns an error if the code section is not found. /// - Returns an error if the local function index is not in the code section. diff --git a/src/lib.rs b/src/lib.rs index 237cd52..312483d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ //! # WASM Injector -//! +//! //! This crate provides a library for injecting WebAssembly modules with //! predefined injections. The injections are primarily meant to be used for testing polkadot parachains hosts. //! # Example //! ``` //! use wasm_injector::{load_module_from_wasm, save_module_to_wasm, Injection}; -//! +//! //! let mut module = load_module_from_wasm(source.as_path())?; // supply your own path here //! let injection = Injection::Noops; // choose your injection //! injection.inject(&mut module)?; // inject the module @@ -16,11 +16,10 @@ pub mod injecting; pub mod stack_limiter; pub mod util; - +pub use self::injecting::injections::Injection; pub use self::util::blob_from_module; -pub use self::util::module_from_blob; +pub use self::util::hexify_bytes; pub use self::util::load_module_from_wasm; +pub use self::util::module_from_blob; pub use self::util::save_module_to_wasm; -pub use self::util::hexify_bytes; pub use self::util::unhexify_bytes; -pub use self::injecting::injections::Injection; diff --git a/src/util.rs b/src/util.rs index 736ba1d..c8e34e9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,9 +10,9 @@ use wasm_instrument::parity_wasm::{deserialize_buffer, elements::Module}; /// # Save bytes to a file in the given path /// It will recursively create parent directories if needed, open and write to the file -/// +/// /// # Errors -/// +/// /// - If the file could not be opened or written to it will return an error /// - If the parent directories could not be created it will return an error pub fn save(path: &Path, bytes: &[u8]) -> Result<(), String> { @@ -34,9 +34,9 @@ pub fn save(path: &Path, bytes: &[u8]) -> Result<(), String> { } /// # Get the filename from a path -/// +/// /// # Errors -/// +/// /// - If the path is not a file it will return an error /// - If the filename could not be converted to a string it will return an error pub fn get_file_name(path: &Path) -> Result<&str, String> { @@ -61,9 +61,9 @@ pub fn modify_file_name(path: &Path, mapper: impl Fn(&str) -> String) -> Result< } /// # Extract the module from the (maybe hexified) (maybe compressed) WASM bytes -/// +/// /// # Errors -/// +/// /// - If the bytes could not be unhexified it will return an error /// - If the bytes could not be decompressed it will return an error /// - If the bytes could not be deserialized it will return an error @@ -85,7 +85,7 @@ pub fn module_from_blob(blob_bytes: &[u8]) -> Result { } /// # Serialize the module into bytes -/// +/// /// # Errors /// - If the module could not be serialized it will return an error pub fn blob_from_module(module: Module) -> Result, String> { @@ -93,7 +93,7 @@ pub fn blob_from_module(module: Module) -> Result, String> { } /// #Load a module from a wasm file in the given path -/// +/// /// # Errors /// - If the file could not be read it will return an error /// - If the module could not be deserialized it will return an error @@ -109,7 +109,7 @@ pub fn load_module_from_wasm(path: &Path) -> Result { } /// # Save a module to a wasm file in the given path -/// +/// /// # Errors /// - If the module could not be compressed it will return an error pub fn save_module_to_wasm( @@ -142,7 +142,7 @@ pub fn save_module_to_wasm( } /// function hexify_bytes -/// +/// /// Takes in bytes and returns a hexified version of them pub fn hexify_bytes(bytes: Vec) -> Vec { let mut hexified_bytes = bytes @@ -158,7 +158,7 @@ pub fn hexify_bytes(bytes: Vec) -> Vec { } /// function unhexify_bytes -/// +/// /// Takes in hexified bytes and returns the original bytes pub fn unhexify_bytes(bytes: Vec) -> Result, String> { bytes