diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 8e4aee563..644f71a93 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -39,6 +39,7 @@ worker-sys = { path = "../worker-sys", version = "0.0.12" } [dependencies.web-sys] version = "0.3.63" features = [ + "Crypto", "File", "WorkerGlobalScope", "ReadableStreamDefaultReader", diff --git a/worker/src/crypto.rs b/worker/src/crypto.rs new file mode 100644 index 000000000..d4a71c1ba --- /dev/null +++ b/worker/src/crypto.rs @@ -0,0 +1,6 @@ +use wasm_bindgen::JsCast; + +pub fn crypto() -> web_sys::Crypto { + let global: web_sys::WorkerGlobalScope = js_sys::global().unchecked_into(); + global.crypto().expect("failed to acquire Crypto") +} diff --git a/worker/src/lib.rs b/worker/src/lib.rs index 9159a5c03..bf39946d8 100644 --- a/worker/src/lib.rs +++ b/worker/src/lib.rs @@ -25,6 +25,7 @@ pub use crate::abort::*; pub use crate::cache::{Cache, CacheDeletionOutcome, CacheKey}; pub use crate::context::Context; pub use crate::cors::Cors; +pub use crate::crypto::*; #[cfg(feature = "d1")] pub use crate::d1::*; pub use crate::date::{Date, DateInit}; @@ -55,6 +56,7 @@ mod cache; mod cf; mod context; mod cors; +mod crypto; // Require pub module for macro export #[cfg(feature = "d1")] pub mod d1;