crypto/random: minor. comments.
This commit is contained in:
parent
76679a0650
commit
76eb6b354b
@ -14,21 +14,21 @@
|
||||
const crypto = global.crypto || global.msCrypto || {};
|
||||
|
||||
/**
|
||||
* Generate some random bytes.
|
||||
* Generate pseudo-random bytes.
|
||||
* @param {Number} size
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.randomBytes = function randomBytes(n) {
|
||||
let data = new Uint8Array(n);
|
||||
exports.randomBytes = function randomBytes(size) {
|
||||
let data = new Uint8Array(size);
|
||||
crypto.getRandomValues(data);
|
||||
return Buffer.from(data.buffer);
|
||||
};
|
||||
|
||||
if (!crypto.getRandomValues) {
|
||||
// Out of luck here. Use bad randomness for now.
|
||||
exports.randomBytes = function randomBytes(n) {
|
||||
let data = Buffer.allocUnsafe(n);
|
||||
exports.randomBytes = function randomBytes(size) {
|
||||
let data = Buffer.allocUnsafe(size);
|
||||
|
||||
for (let i = 0; i < data.length; i++)
|
||||
data[i] = Math.floor(Math.random() * 256);
|
||||
|
||||
@ -12,8 +12,11 @@
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
/*
|
||||
* Misc
|
||||
/**
|
||||
* Generate pseudo-random bytes.
|
||||
* @function
|
||||
* @param {Number} size
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.randomBytes = crypto.randomBytes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user