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