Fix rng def in nodejs environment.

This commit is contained in:
Andrey Antukh 2016-04-24 22:53:31 +03:00
parent f0ed85e53f
commit ac3d44601a
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

12
vendor/uuid/rng.js vendored
View file

@ -9,23 +9,25 @@
"use strict"; "use strict";
goog.provide("uuid.rng"); goog.provide("uuid.rng");
goog.require("cljs.core");
goog.scope(function() { goog.scope(function() {
uuid.rng.getBytes = null; const global = goog.global;
// Check if nodejs rng is available (high quality); // Check if nodejs rng is available (high quality);
if (goog.global.require !== undefined) { if (cljs.core._STAR_target_STAR_ === "nodejs") {
const crypto = goog.global.require("crypto"); const crypto = require("crypto");
uuid.rng.getBytes = function(n) { uuid.rng.getBytes = function(n) {
return crypto.randomBytes(n); return crypto.randomBytes(n);
}; };
} }
// Check if whatwg rng is available (high quality); // Check if whatwg rng is available (high quality);
else if (goog.global.crypto.getRandomValues !== undefined) { else if (global.crypto !== undefined &&
global.crypto.getRandomValues !== undefined) {
uuid.rng.getBytes = function(n) { uuid.rng.getBytes = function(n) {
const buf = new Uint8Array(16); const buf = new Uint8Array(16);
goog.global.crypto.getRandomValues(buf); global.crypto.getRandomValues(buf);
return buf; return buf;
}; };
} }