Skip to content

Commit 4d5da7a

Browse files
committed
Just one if to check whether crypto is defined.
1 parent 3cbd6c1 commit 4d5da7a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Diff for: src/core.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ var CryptoJS = CryptoJS || (function (Math, undefined) {
3737
}
3838
} catch (err) {}
3939

40-
// Use getRandomValues method
41-
if (crypto && typeof crypto.getRandomValues === 'function') {
42-
try {
43-
return crypto.getRandomValues(new Uint32Array(1))[0];
44-
} catch (err) {}
45-
}
40+
if (crypto) {
41+
// Use getRandomValues method
42+
if (typeof crypto.getRandomValues === 'function') {
43+
try {
44+
return crypto.getRandomValues(new Uint32Array(1))[0];
45+
} catch (err) {}
46+
}
4647

47-
// Use randomBytes method
48-
if (crypto && typeof crypto.randomBytes === 'function') {
49-
try {
50-
return crypto.randomBytes(4).readInt32LE();
51-
} catch (err) {}
48+
// Use randomBytes method
49+
if (typeof crypto.randomBytes === 'function') {
50+
try {
51+
return crypto.randomBytes(4).readInt32LE();
52+
} catch (err) {}
53+
}
5254
}
5355

5456
throw new Error('Native crypto module could not be used to get secure random number.');

0 commit comments

Comments
 (0)