From 15ce07dc2e2648684018325044884daac883c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 2 Dec 2024 19:34:07 +0300 Subject: [PATCH 1/2] wasm_js: remove IE 11 workaround --- src/backends/wasm_js.rs | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/backends/wasm_js.rs b/src/backends/wasm_js.rs index c0182b824..15a4e66bb 100644 --- a/src/backends/wasm_js.rs +++ b/src/backends/wasm_js.rs @@ -83,29 +83,23 @@ fn getrandom_init() -> Result { // Get the Web Crypto interface if we are in a browser, Web Worker, Deno, // or another environment that supports the Web Cryptography API. This // also allows for user-provided polyfills in unsupported environments. - let crypto = match global.crypto() { - // Standard Web Crypto interface - c if c.is_object() => c, - // Node.js CommonJS Crypto module - _ if is_node(&global) => { - // If module.require isn't a valid function, we are in an ES module. - match Module::require_fn().and_then(JsCast::dyn_into::) { - Ok(require_fn) => match require_fn.call1(&global, &JsValue::from_str("crypto")) { - Ok(n) => return Ok(RngSource::Node(n.unchecked_into())), - Err(_) => return Err(Error::NODE_CRYPTO), - }, - Err(_) => return Err(Error::NODE_ES_MODULE), - } - } - // IE 11 Workaround - _ => match global.ms_crypto() { - c if c.is_object() => c, - _ => return Err(Error::WEB_CRYPTO), - }, - }; - - let buf = Uint8Array::new_with_length(WEB_CRYPTO_BUFFER_SIZE.into()); - Ok(RngSource::Web(crypto, buf)) + let crypto = global.crypto(); + if crypto.is_object() { + let buf = Uint8Array::new_with_length(WEB_CRYPTO_BUFFER_SIZE.into()); + Ok(RngSource::Web(crypto, buf)) + } else if is_node(&global) { + // If module.require isn't a valid function, we are in an ES module. + let require_fn = Module::require_fn() + .and_then(JsCast::dyn_into::) + .map_err(|_| Error::NODE_ES_MODULE)?; + let n = require_fn + .call1(&global, &JsValue::from_str("crypto")) + .map_err(|_| Error::NODE_CRYPTO)? + .unchecked_into(); + Ok(RngSource::Node(n)) + } else { + Err(Error::WEB_CRYPTO) + } } // Taken from https://www.npmjs.com/package/browser-or-node From da4461381f9f95a04db83b4a681cbb6068f33828 Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Mon, 2 Dec 2024 19:48:16 +0300 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c01987b18..01de288e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 in favor of configuration flags [#504] - `register_custom_getrandom!` macro [#504] - Implementation of `From` for `Error` and `Error::code` method [#507] +- Internet Explorer 11 support [#554] ### Changed - Use `ProcessPrng` on Windows 10 and up, and use RtlGenRandom on older legacy Windows versions [#415] @@ -52,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#532]: https://github.com/rust-random/getrandom/pull/532 [#542]: https://github.com/rust-random/getrandom/pull/542 [#544]: https://github.com/rust-random/getrandom/pull/544 +[#554]: https://github.com/rust-random/getrandom/pull/554 ## [0.2.15] - 2024-05-06 ### Added