@@ -60,17 +60,17 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
6060fn getrandom_init ( ) -> Result < RngSource , Error > {
6161 if let Ok ( self_) = Global :: get_self ( ) {
6262 // If `self` is defined then we're in a browser somehow (main window
63- // or web worker). Here we want to try to use
64- // `crypto.getRandomValues`, but if `crypto` isn't defined we assume
65- // we're in an older web browser and the OS RNG isn't available.
66-
67- let crypto = self_. crypto ( ) ;
68- if crypto. is_undefined ( ) {
69- return Err ( BINDGEN_CRYPTO_UNDEF ) ;
70- }
63+ // or web worker). We get `self.crypto` (called `msCrypto` on IE), so we
64+ // can call `crypto.getRandomValues`. If `crypto` isn't defined, we
65+ // assume we're in an older web browser and the OS RNG isn't available.
66+
67+ let crypto: BrowserCrypto = match ( self_. crypto ( ) , self_. ms_crypto ( ) ) {
68+ ( crypto, _) if !crypto. is_undefined ( ) => crypto. into ( ) ,
69+ ( _, crypto) if !crypto. is_undefined ( ) => crypto. into ( ) ,
70+ _ => return Err ( BINDGEN_CRYPTO_UNDEF ) ,
71+ } ;
7172
7273 // Test if `crypto.getRandomValues` is undefined as well
73- let crypto: BrowserCrypto = crypto. into ( ) ;
7474 if crypto. get_random_values_fn ( ) . is_undefined ( ) {
7575 return Err ( BINDGEN_GRV_UNDEF ) ;
7676 }
@@ -88,6 +88,8 @@ extern "C" {
8888 fn get_self ( ) -> Result < Self_ , JsValue > ;
8989
9090 type Self_ ;
91+ #[ wasm_bindgen( method, getter, js_name = "msCrypto" , structural) ]
92+ fn ms_crypto ( me : & Self_ ) -> JsValue ;
9193 #[ wasm_bindgen( method, getter, structural) ]
9294 fn crypto ( me : & Self_ ) -> JsValue ;
9395
0 commit comments