22
33// limit of Crypto.getRandomValues()
44// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
5- var MAX_BYTES = 65536
5+ const MAX_BYTES = 65536
66
77// Node supports requesting up to this number of bytes
88// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
9- var MAX_UINT32 = 4294967295
9+ const MAX_UINT32 = 4294967295
1010
1111function oldBrowser ( ) {
1212 throw new Error ( 'Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11' )
1313}
1414
15- var crypto = global . crypto || global . msCrypto
15+ const crypto = global . crypto || global . msCrypto
1616
1717if ( crypto && crypto . getRandomValues ) {
1818 module . exports = randomBytes
@@ -24,12 +24,12 @@ function randomBytes (size, cb) {
2424 // phantomjs needs to throw
2525 if ( size > MAX_UINT32 ) throw new RangeError ( 'requested too many random bytes' )
2626
27- var bytes = Buffer . allocUnsafe ( size )
27+ const bytes = Buffer . allocUnsafe ( size )
2828
29- if ( size > 0 ) { // getRandomValues fails on IE if size == 0
29+ if ( size > 0 ) { // getRandomValues fails on IE if size == 0
3030 if ( size > MAX_BYTES ) { // this is the max bytes crypto.getRandomValues
3131 // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
32- for ( var generated = 0 ; generated < size ; generated += MAX_BYTES ) {
32+ for ( let generated = 0 ; generated < size ; generated += MAX_BYTES ) {
3333 // buffer.slice automatically checks if the end is past the end of
3434 // the buffer so we don't have to here
3535 crypto . getRandomValues ( bytes . slice ( generated , generated + MAX_BYTES ) )
0 commit comments