Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Burke <me@reidburke.com>2011-02-08 23:37:13 +0300
committerisaacs <i@izs.me>2011-02-09 04:36:24 +0300
commite297e13520af3b4e00a4291f096d9d6d66f57f1f (patch)
tree0188795a778b7ad1f2c07c7b1e852be93a3559de
parentdf8a7d954367946a7d6bee2c32f7208f2cb99c72 (diff)
Closes GH-564 Use the MIT node-uuid lib instead of OSLv3 uuid.js.
-rw-r--r--LICENSE4
-rw-r--r--lib/utils/registry/adduser.js2
-rw-r--r--lib/utils/uuid.js118
3 files changed, 89 insertions, 35 deletions
diff --git a/LICENSE b/LICENSE
index 43611a255..d9360f8c5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -17,3 +17,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
+
+
+This software contains the node-uuid library.
+Copyright 2010 Robert Kieffer. Dual licensed under the MIT and GPL licenses.
diff --git a/lib/utils/registry/adduser.js b/lib/utils/registry/adduser.js
index 22f7695b3..0cda561bf 100644
--- a/lib/utils/registry/adduser.js
+++ b/lib/utils/registry/adduser.js
@@ -22,7 +22,7 @@ function adduser (username, password, email, cb) {
if (password.indexOf(":") !== -1) return cb(new Error(
"Sorry, ':' chars are not allowed in passwords.\n"+
"See <https://issues.apache.org/jira/browse/COUCHDB-969> for why."))
- var salt = uuid.generate()
+ var salt = uuid()
, userobj =
{ name : username
, salt : salt
diff --git a/lib/utils/uuid.js b/lib/utils/uuid.js
index e2081ce33..54bfd5be0 100644
--- a/lib/utils/uuid.js
+++ b/lib/utils/uuid.js
@@ -1,34 +1,84 @@
-/* randomUUID.js - Version 1.0
- *
- * Copyright 2008, Robert Kieffer
- *
- * This software is made available under the terms of the Open Software License
- * v3.0 (available here: http://www.opensource.org/licenses/osl-3.0.php )
- *
- * The latest version of this file can be found at:
- * http://www.broofa.com/Tools/randomUUID.js
- *
- * For more information, or to comment on this, please go to:
- * http://www.broofa.com/blog/?p=151
- */
-
-/**
- * Create and return a "version 4" RFC-4122 UUID string.
- */
-
-function randomUUID() {
- var s = [], itoh = '0123456789ABCDEF';
- // Make array of random hex digits. The UUID only has 32 digits in it, but we
- // allocate an extra items to make room for the '-'s we'll be inserting.
- for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
- // Conform to RFC-4122, section 4.4
- s[14] = 4; // Set 4 high bits of time_high field to version
- s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
- // Convert to hex chars
- for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
- // Insert '-'s
- s[8] = s[13] = s[18] = s[23] = '-';
- return s.join('');
-}
-
-exports.generate = function () {return randomUUID();} \ No newline at end of file
+(function() {
+ /*
+ * Generate a RFC4122(v4) UUID
+ *
+ * Documentation at https://github.com/broofa/node-uuid
+ *
+ * Copyright 2010 Robert Kieffer
+ * Dual licensed under the MIT and GPL licenses.
+ */
+
+ // Use node.js Buffer class if available, otherwise use the Array class
+ var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array;
+
+ // Buffer used for generating string uuids
+ var _buf = new BufferClass(16);
+
+ // Cache number <-> hex string for octet values
+ var toString = [];
+ var toNumber = {};
+ for (var i = 0; i < 256; i++) {
+ toString[i] = (i + 0x100).toString(16).substr(1).toUpperCase();
+ toNumber[toString[i]] = i;
+ }
+
+ function parse(s) {
+ var buf = new BufferClass(16);
+ var i = 0, ton = toNumber;
+ s.toUpperCase().replace(/[0-9A-F][0-9A-F]/g, function(octet) {
+ buf[i++] = toNumber[octet];
+ });
+ return buf;
+ }
+
+ function unparse(buf) {
+ var tos = toString, b = buf;
+ return tos[b[0]] + tos[b[1]] + tos[b[2]] + tos[b[3]] + '-' +
+ tos[b[4]] + tos[b[5]] + '-' +
+ tos[b[6]] + tos[b[7]] + '-' +
+ tos[b[8]] + tos[b[9]] + '-' +
+ tos[b[10]] + tos[b[11]] + tos[b[12]] +
+ tos[b[13]] + tos[b[14]] + tos[b[15]];
+ }
+
+ function uuid(fmt, buf, offset) {
+ var b32 = 0x100000000, ff = 0xff;
+
+ var b = fmt != 'binary' ? _buf : (buf ? buf : new BufferClass(16));
+ var i = buf && offset || 0;
+
+ r = Math.random()*b32;
+ b[i++] = r & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+ r = Math.random()*b32;
+ b[i++] = r & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & 0x0f | 0x40; // See RFC4122 sect. 4.1.3
+ b[i++] = (r=r>>>8) & ff;
+ r = Math.random()*b32;
+ b[i++] = r & 0x3f | 0x80; // See RFC4122 sect. 4.4
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+ r = Math.random()*b32;
+ b[i++] = r & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+ b[i++] = (r=r>>>8) & ff;
+
+ return fmt === undefined ? unparse(b) : b;
+ };
+
+ uuid.parse = parse;
+ uuid.unparse = unparse;
+ uuid.BufferClass = BufferClass;
+
+ if (typeof(module) != 'undefined') {
+ module.exports = uuid;
+ } else {
+ // In browser? Set as top-level function
+ this.uuid = uuid;
+ }
+})();