Repository navigation
Release v0.2.1
Fix Crash When Executing as WebAssembly by Adding Support for Time Retrieval in Browser Environment
Description:
This pull request addresses an issue where the jwt-rustcrypto library would crash when executed as WebAssembly (WASM) in the browser. The crash was caused by the library's reliance on system time, which is not accessible in the same way within a browser environment. To resolve this, modifications were made to allow the library to retrieve the current timestamp using browser-compatible methods when compiled for WebAssembly.
Changes:
- Cargo.toml:
- Bumped the version from
0.2.0to0.2.1. - Added
wasm-bindgenas a dependency to enable interfacing with JavaScript functions for browser compatibility.
- Bumped the version from
- Cargo.lock:
- Updated to reflect changes in dependencies.
- src/validation.rs:
- Implemented conditional compilation to differentiate between standard system time access (
std::time::SystemTime) and WebAssembly-compatible time retrieval usingwasm-bindgen. - Added new functions to retrieve the current timestamp using JavaScript's
Date.now()method when running in a WASM environment. - Included a conditional import of
wasm-bindgen::prelude::*for WebAssembly-specific functionalities. - Improved error handling and ensured consistent behavior across environments.
- Implemented conditional compilation to differentiate between standard system time access (