Skip to content

Commit

Permalink
eslint (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa authored Oct 2, 2017
1 parent bba9402 commit 815daa3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
18 changes: 12 additions & 6 deletions lib/md5.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ var crypto = require('crypto');

function md5(bytes) {
if (typeof Buffer.from === 'function') {
// Support modern Buffer API
if (Array.isArray(bytes)) bytes = Buffer.from(bytes);
else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8');
// Modern Buffer API
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}
} else {
// Support pre-v4 Buffer API
if (Array.isArray(bytes)) bytes = new Buffer(bytes);
else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8');
// Pre-v4 Buffer API
if (Array.isArray(bytes)) {
bytes = new Buffer(bytes);
} else if (typeof bytes === 'string') {
bytes = new Buffer(bytes, 'utf8');
}
}

return crypto.createHash('md5').update(bytes).digest();
Expand Down
18 changes: 12 additions & 6 deletions lib/sha1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ var crypto = require('crypto');

function sha1(bytes) {
if (typeof Buffer.from === 'function') {
// Support modern Buffer API
if (Array.isArray(bytes)) bytes = Buffer.from(bytes);
else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8');
// Modern Buffer API
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}
} else {
// Support pre-v4 Buffer API
if (Array.isArray(bytes)) bytes = new Buffer(bytes);
else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8');
// Pre-v4 Buffer API
if (Array.isArray(bytes)) {
bytes = new Buffer(bytes);
} else if (typeof bytes === 'string') {
bytes = new Buffer(bytes, 'utf8');
}
}

return crypto.createHash('sha1').update(bytes).digest();
Expand Down
2 changes: 0 additions & 2 deletions lib/v35.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ function stringToBytes(str) {
return bytes;
}



module.exports = function(name, version, hashfunc) {
var generateUUID = function(value, namespace, buf, offset) {
var off = buf && offset || 0;
Expand Down
15 changes: 6 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assert = require('assert');
var crypto = require('crypto');

var uuid = require('../');
var crypto = require('crypto');
Expand Down Expand Up @@ -72,8 +73,11 @@ test('mathRNG', function() {
});

test('cryptoRNG', function() {
// Clear require cache so we can monkey with it, below
delete require.cache[require.resolve('../lib/rng-browser')];
var randomFillSync = crypto.randomFillSync;

Object.keys(require.cache).forEach(function(path) {
if (/rng-browser/.test(path)) delete require.cache[path];
});

// We shim the web crypto API to trigger cryptoRNG code path in rng module,
// then unshim once we've required it
Expand All @@ -90,13 +94,6 @@ test('cryptoRNG', function() {
delete global.crypto;

assert.equal(rng.name, 'whatwgRNG');

var bytes = rng();
assert.equal(bytes.length, 16);

for (var i = 0; i < bytes.length; i++) {
assert.equal(typeof(bytes[i]), 'number');
}
});

test('sha1 node', function() {
Expand Down

0 comments on commit 815daa3

Please sign in to comment.