Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use the MIT node-uuid library #564

Closed
wants to merge 1 commit into from

2 participants

@reid

The existing uuid.js is licensed under OSLv3, which is pretty complicated compared to MIT.

The same author wrote its successor, node-uuid, which is dual licensed under MIT and GPL. Let's use that instead?

@reid

Closed by e297e13 Use the MIT node-uuid lib instead of OSLv3 uuid.js.

@josephboyle

Getting build error:

$ make
! [ -d .git ] || git submodule update --init
Initialized empty Git repository in /Users/josephboyle/npm/node_modules/node-uuid/.git/
error: The requested URL returned error: 403 while accessing http://github.com/broofa/node-uuid/info/refs

fatal: HTTP request failed
Clone of 'http://github.com/broofa/node-uuid' into submodule path 'node_modules/node-uuid' failed
make: *** [submodules] Error 1

@reid reid referenced this pull request from a commit in reid/npm
@reid reid Closes GH-564 Use the MIT node-uuid lib instead of OSLv3 uuid.js. e297e13
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2011
  1. @reid
This page is out of date. Refresh to see the latest.
Showing with 89 additions and 35 deletions.
  1. +4 −0 LICENSE
  2. +1 −1  lib/utils/registry/adduser.js
  3. +84 −34 lib/utils/uuid.js
View
4 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.
View
2  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
View
118 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();}
+(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;
+ }
+})();
Something went wrong with that request. Please try again.