[Pkg-javascript-commits] [sockjs-client] 45/350: only test for crypto once

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 3332d8a2c3b79ca4c6ff5704af43fa2793bf3f1d
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Mon May 19 11:14:56 2014 -0400

    only test for crypto once
---
 lib/utils.js | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/lib/utils.js b/lib/utils.js
index 30c240e..85ca70e 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -9,23 +9,29 @@
 // This string has length 32, a power of 2, so the modulus doesn't introduce a
 // bias.
 var random_string_chars = 'abcdefghijklmnopqrstuvwxyz012345';
-utils.random_string = function(length) {
-    var max = random_string_chars.length;
-    var i, bytes, ret = [];
-    // Use real randomness when available.
-    if (_window.crypto && _window.crypto.getRandomValues) {
-        bytes = new Uint8Array(length);
+// Use real randomness when available.
+if (_window.crypto && _window.crypto.getRandomValues) {
+    utils.random_string = function(length) {
+        var max = random_string_chars.length;
+        var ret = [];
+        var bytes = new Uint8Array(length);
+
         _window.crypto.getRandomValues(bytes);
-        for(i=0; i < length; i++) {
+        for(var i=0; i < length; i++) {
             ret.push( random_string_chars[bytes[i] % max] );
         }
-    } else {
-        for(i=0; i < length; i++) {
+        return ret.join('');
+    };
+} else {
+    utils.random_string = function(length) {
+        var max = random_string_chars.length;
+        var ret = [];
+        for(var i=0; i < length; i++) {
             ret.push( random_string_chars[Math.floor(Math.random() * max)] );
         }
-    }
-    return ret.join('');
-};
+        return ret.join('');
+    };
+}
 utils.random_number = function(max) {
     return Math.floor(Math.random() * max);
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list