()
| 1173 | }}; |
| 1174 | |
| 1175 | function initRandomFill() { |
| 1176 | if (typeof crypto == 'object' && typeof crypto['getRandomValues'] == 'function') { |
| 1177 | // for modern web browsers |
| 1178 | return (view) => crypto.getRandomValues(view); |
| 1179 | } else |
| 1180 | if (ENVIRONMENT_IS_NODE) { |
| 1181 | // for nodejs with or without crypto support included |
| 1182 | try { |
| 1183 | var crypto_module = require('crypto'); |
| 1184 | var randomFillSync = crypto_module['randomFillSync']; |
| 1185 | if (randomFillSync) { |
| 1186 | // nodejs with LTS crypto support |
| 1187 | return (view) => crypto_module['randomFillSync'](view); |
| 1188 | } |
| 1189 | // very old nodejs with the original crypto API |
| 1190 | var randomBytes = crypto_module['randomBytes']; |
| 1191 | return (view) => ( |
| 1192 | view.set(randomBytes(view.byteLength)), |
| 1193 | // Return the original view to match modern native implementations. |
| 1194 | view |
| 1195 | ); |
| 1196 | } catch (e) { |
| 1197 | // nodejs doesn't have crypto support |
| 1198 | } |
| 1199 | } |
| 1200 | // we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096 |
| 1201 | abort("no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: function(array) { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };"); |
| 1202 | } |
| 1203 | function randomFill(view) { |
| 1204 | // Lazily init on the first invocation. |
| 1205 | return (randomFill = initRandomFill())(view); |
no test coverage detected