Skip to content

Commit 153d331

Browse files
robwierzbowskibroofa
authored andcommitted
fix: Get correct version of IE11 crypto (#274)
Users on Windows 7 and IE11 sometimes trigger a bind error because the crypto object exists but getRandomValues is undefined. Using openpgpjs/openpgpjs#207 as a reference, I've added a more robust check for the necessary crypto properties in IE 11.
1 parent df40e54 commit 153d331

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/rng-browser.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// and inconsistent support for the `crypto` API. We do the best we can via
44
// feature-detection
55

6-
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
7-
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues.bind(crypto)) ||
8-
(typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues.bind(msCrypto));
6+
// getRandomValues needs to be invoked in a context where "this" is a Crypto
7+
// implementation. Also, find the complete implementation of crypto on IE11.
8+
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
9+
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
10+
911
if (getRandomValues) {
1012
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
1113
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef

0 commit comments

Comments
 (0)