From f81542a792ca0d664e0ab697845d504272d352a5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 22 Jun 2016 00:08:08 +0300 Subject: [PATCH] Rename uuid related namespaces. --- src/uxbox/util/{uuid/rng.js => rng_impl.js} | 11 +++++------ src/uxbox/util/uuid.cljs | 2 +- src/uxbox/util/{uuid/impl.js => uuid_impl.js} | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) rename src/uxbox/util/{uuid/rng.js => rng_impl.js} (87%) rename src/uxbox/util/{uuid/impl.js => uuid_impl.js} (86%) diff --git a/src/uxbox/util/uuid/rng.js b/src/uxbox/util/rng_impl.js similarity index 87% rename from src/uxbox/util/uuid/rng.js rename to src/uxbox/util/rng_impl.js index 995c44eb5..d124b728d 100644 --- a/src/uxbox/util/uuid/rng.js +++ b/src/uxbox/util/rng_impl.js @@ -8,19 +8,18 @@ "use strict"; -goog.provide("uxbox.util.uuid.rng"); +goog.provide("uxbox.util.rng_impl"); goog.require("cljs.core"); goog.scope(function() { + const self = uxbox.util.rng_impl; const global = goog.global; - const rng = uxbox.util.uuid.rng; - // Check if nodejs rng is available (high quality); if (cljs.core._STAR_target_STAR_ === "nodejs") { const crypto = require("crypto"); - rng.getBytes = function(n) { + self.getBytes = function(n) { return crypto.randomBytes(n); }; } @@ -28,7 +27,7 @@ goog.scope(function() { // Check if whatwg rng is available (high quality); else if (global.crypto !== undefined && global.crypto.getRandomValues !== undefined) { - rng.getBytes = function(n) { + self.getBytes = function(n) { const buf = new Uint8Array(16); global.crypto.getRandomValues(buf); return buf; @@ -38,7 +37,7 @@ goog.scope(function() { // Switch Back to the Math.random (low quality); else { console.warn("No high quality RNG available, switching back to Math.random."); - rng.getBytes = function(n) { + self.getBytes = function(n) { const buf = new Array(n); for (let i = 0, r; i < n; i++) { if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; } diff --git a/src/uxbox/util/uuid.cljs b/src/uxbox/util/uuid.cljs index 00fea32c9..db225b57e 100644 --- a/src/uxbox/util/uuid.cljs +++ b/src/uxbox/util/uuid.cljs @@ -13,7 +13,7 @@ If no high qualiry RNG, switches to the default Math based RNG with proper waring in the console." - (:require [uxbox.util.uuid.impl :as impl])) + (:require [uxbox.util.uuid-impl :as impl])) (defn v4 "Generate a v4 (random) UUID." diff --git a/src/uxbox/util/uuid/impl.js b/src/uxbox/util/uuid_impl.js similarity index 86% rename from src/uxbox/util/uuid/impl.js rename to src/uxbox/util/uuid_impl.js index a0806aaf9..a552d46d0 100644 --- a/src/uxbox/util/uuid/impl.js +++ b/src/uxbox/util/uuid_impl.js @@ -7,14 +7,14 @@ */ "use strict"; -goog.provide("uxbox.util.uuid.impl"); -goog.require("uxbox.util.uuid.rng"); +goog.provide("uxbox.util.uuid_impl"); +goog.require("uxbox.util.rng_impl"); goog.scope(function() { - const impl = uxbox.util.uuid.impl; - const rng = uxbox.util.uuid.rng; - const hexMap = []; + const self = uxbox.util.uuid_impl; + const rng = uxbox.util.rng_impl; + const hexMap = []; for (let i = 0; i < 256; i++) { hexMap[i] = (i + 0x100).toString(16).substr(1); } @@ -39,7 +39,7 @@ goog.scope(function() { hexMap[buf[i++]]); } - impl.v4 = function() { + self.v4 = function() { const buf = rng.getBytes(16); buf[6] = (buf[6] & 0x0f) | 0x40; buf[8] = (buf[8] & 0x3f) | 0x80;