Skip to content

Commit bba9402

Browse files
authored
eslint (uuid-rs#219)
* eslint * s/;// * eslint * s/;// * Add eqeqeq, brace-style, and one-var rules * fix broken test (not related to eslint) * fix test for real
1 parent 0ea33e6 commit bba9402

12 files changed

+204
-187
lines changed

.eslintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"mocha": true
88
},
99
"extends": ["eslint:recommended"],
10-
"installedESLint": true,
1110
"rules": {
1211
"array-bracket-spacing": ["warn", "never"],
1312
"arrow-body-style": ["warn", "as-needed"],
1413
"arrow-parens": ["warn", "as-needed"],
1514
"arrow-spacing": "warn",
16-
"brace-style": "warn",
15+
"brace-style": ["warn", "1tbs"],
1716
"camelcase": "warn",
1817
"comma-spacing": ["warn", {"after": true}],
1918
"dot-notation": "warn",
19+
"eqeqeq": ["warn", "smart"],
2020
"indent": ["warn", 2, {
2121
"SwitchCase": 1,
2222
"FunctionDeclaration": {"parameters": 1},
@@ -33,6 +33,7 @@
3333
"no-trailing-spaces": "warn",
3434
"no-undef": "error",
3535
"no-unused-vars": ["warn", {"args": "none"}],
36+
"one-var": ["warn", "never"],
3637
"padded-blocks": ["warn", "never"],
3738
"object-curly-spacing": ["warn", "never"],
3839
"quotes": ["warn", "single"],

lib/md5-browser.js

Lines changed: 131 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
* See http://pajhome.org.uk/crypt/md5 for more info.
2020
*/
2121

22-
'use strict;'
22+
'use strict';
2323

2424
function md5(bytes) {
25-
2625
if (typeof(bytes) == 'string') {
2726
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
2827
bytes = new Array(msg.length);
@@ -32,187 +31,186 @@ function md5(bytes) {
3231
return md5ToHexEncodedArray(
3332
wordsToMd5(
3433
bytesToWords(bytes)
35-
, bytes.length * 8)
36-
)
34+
, bytes.length * 8)
35+
);
3736
}
3837

3938

40-
/*
39+
/*
4140
* Convert an array of little-endian words to an array of bytes
4241
*/
4342
function md5ToHexEncodedArray(input) {
44-
var i
45-
var x
46-
var output = []
47-
var length32 = input.length * 32
48-
var hexTab = '0123456789abcdef'
49-
var hex
43+
var i;
44+
var x;
45+
var output = [];
46+
var length32 = input.length * 32;
47+
var hexTab = '0123456789abcdef';
48+
var hex;
5049

5150
for (i = 0; i < length32; i += 8) {
52-
x = (input[i >> 5] >>> (i % 32)) & 0xFF
51+
x = (input[i >> 5] >>> (i % 32)) & 0xFF;
5352

54-
hex = parseInt(hexTab.charAt((x >>> 4) & 0x0F) + hexTab.charAt(x & 0x0F), 16)
53+
hex = parseInt(hexTab.charAt((x >>> 4) & 0x0F) + hexTab.charAt(x & 0x0F), 16);
5554

56-
output.push(hex)
55+
output.push(hex);
5756
}
58-
return output
57+
return output;
5958
}
6059

61-
/*
60+
/*
6261
* Calculate the MD5 of an array of little-endian words, and a bit length.
6362
*/
64-
function wordsToMd5 (x, len) {
63+
function wordsToMd5(x, len) {
6564
/* append padding */
66-
x[len >> 5] |= 0x80 << (len % 32)
67-
x[(((len + 64) >>> 9) << 4) + 14] = len
65+
x[len >> 5] |= 0x80 << (len % 32);
66+
x[(((len + 64) >>> 9) << 4) + 14] = len;
6867

69-
var i
70-
var olda
71-
var oldb
72-
var oldc
73-
var oldd
74-
var a = 1732584193
75-
var b = -271733879
76-
var c = -1732584194
68+
var i;
69+
var olda;
70+
var oldb;
71+
var oldc;
72+
var oldd;
73+
var a = 1732584193;
74+
var b = -271733879;
75+
var c = -1732584194;
7776

78-
var d = 271733878
77+
var d = 271733878;
7978

8079
for (i = 0; i < x.length; i += 16) {
81-
olda = a
82-
oldb = b
83-
oldc = c
84-
oldd = d
85-
86-
a = md5ff(a, b, c, d, x[i], 7, -680876936)
87-
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586)
88-
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819)
89-
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330)
90-
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897)
91-
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426)
92-
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341)
93-
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983)
94-
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416)
95-
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417)
96-
c = md5ff(c, d, a, b, x[i + 10], 17, -42063)
97-
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162)
98-
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682)
99-
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101)
100-
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290)
101-
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329)
102-
103-
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510)
104-
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632)
105-
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713)
106-
b = md5gg(b, c, d, a, x[i], 20, -373897302)
107-
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691)
108-
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083)
109-
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335)
110-
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848)
111-
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438)
112-
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690)
113-
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961)
114-
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501)
115-
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467)
116-
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784)
117-
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473)
118-
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734)
119-
120-
a = md5hh(a, b, c, d, x[i + 5], 4, -378558)
121-
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463)
122-
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562)
123-
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556)
124-
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060)
125-
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353)
126-
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632)
127-
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640)
128-
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174)
129-
d = md5hh(d, a, b, c, x[i], 11, -358537222)
130-
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979)
131-
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189)
132-
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487)
133-
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835)
134-
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520)
135-
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651)
136-
137-
a = md5ii(a, b, c, d, x[i], 6, -198630844)
138-
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415)
139-
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905)
140-
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055)
141-
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571)
142-
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606)
143-
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523)
144-
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799)
145-
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359)
146-
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744)
147-
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380)
148-
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649)
149-
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070)
150-
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379)
151-
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259)
152-
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551)
153-
154-
a = safeAdd(a, olda)
155-
b = safeAdd(b, oldb)
156-
c = safeAdd(c, oldc)
157-
d = safeAdd(d, oldd)
80+
olda = a;
81+
oldb = b;
82+
oldc = c;
83+
oldd = d;
84+
85+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
86+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
87+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
88+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
89+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
90+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
91+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
92+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
93+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
94+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
95+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
96+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
97+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
98+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
99+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
100+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
101+
102+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
103+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
104+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
105+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
106+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
107+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
108+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
109+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
110+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
111+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
112+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
113+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
114+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
115+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
116+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
117+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
118+
119+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
120+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
121+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
122+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
123+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
124+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
125+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
126+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
127+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
128+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
129+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
130+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
131+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
132+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
133+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
134+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
135+
136+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
137+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
138+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
139+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
140+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
141+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
142+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
143+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
144+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
145+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
146+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
147+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
148+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
149+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
150+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
151+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
152+
153+
a = safeAdd(a, olda);
154+
b = safeAdd(b, oldb);
155+
c = safeAdd(c, oldc);
156+
d = safeAdd(d, oldd);
158157
}
159-
return [a, b, c, d]
158+
return [a, b, c, d];
160159
}
161160

162-
/*
161+
/*
163162
* Convert an array bytes to an array of little-endian words
164163
* Characters >255 have their high-byte silently ignored.
165164
*/
166165
function bytesToWords(input) {
167-
168-
var i
169-
var output = []
170-
output[(input.length >> 2) - 1] = undefined
166+
var i;
167+
var output = [];
168+
output[(input.length >> 2) - 1] = undefined;
171169
for (i = 0; i < output.length; i += 1) {
172-
output[i] = 0
170+
output[i] = 0;
173171
}
174-
var length8 = input.length * 8
172+
var length8 = input.length * 8;
175173
for (i = 0; i < length8; i += 8) {
176-
output[i >> 5] |= (input[(i / 8)] & 0xFF) << (i % 32)
174+
output[i >> 5] |= (input[(i / 8)] & 0xFF) << (i % 32);
177175
}
178176

179-
return output
177+
return output;
180178
}
181179

182180
/*
183181
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
184182
* to work around bugs in some JS interpreters.
185183
*/
186-
function safeAdd (x, y) {
187-
var lsw = (x & 0xFFFF) + (y & 0xFFFF)
188-
var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
189-
return (msw << 16) | (lsw & 0xFFFF)
184+
function safeAdd(x, y) {
185+
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
186+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
187+
return (msw << 16) | (lsw & 0xFFFF);
190188
}
191189

192190
/*
193191
* Bitwise rotate a 32-bit number to the left.
194192
*/
195-
function bitRotateLeft (num, cnt) {
196-
return (num << cnt) | (num >>> (32 - cnt))
193+
function bitRotateLeft(num, cnt) {
194+
return (num << cnt) | (num >>> (32 - cnt));
197195
}
198196

199197
/*
200198
* These functions implement the four basic operations the algorithm uses.
201199
*/
202-
function md5cmn (q, a, b, x, s, t) {
203-
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b)
200+
function md5cmn(q, a, b, x, s, t) {
201+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
202+
}
203+
function md5ff(a, b, c, d, x, s, t) {
204+
return md5cmn((b & c) | ((~b) & d), a, b, x, s, t);
204205
}
205-
function md5ff (a, b, c, d, x, s, t) {
206-
return md5cmn((b & c) | ((~b) & d), a, b, x, s, t)
206+
function md5gg(a, b, c, d, x, s, t) {
207+
return md5cmn((b & d) | (c & (~d)), a, b, x, s, t);
207208
}
208-
function md5gg (a, b, c, d, x, s, t) {
209-
return md5cmn((b & d) | (c & (~d)), a, b, x, s, t)
209+
function md5hh(a, b, c, d, x, s, t) {
210+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
210211
}
211-
function md5hh (a, b, c, d, x, s, t) {
212-
return md5cmn(b ^ c ^ d, a, b, x, s, t)
212+
function md5ii(a, b, c, d, x, s, t) {
213+
return md5cmn(c ^ (b | (~d)), a, b, x, s, t);
213214
}
214-
function md5ii (a, b, c, d, x, s, t) {
215-
return md5cmn(c ^ (b | (~d)), a, b, x, s, t)
216-
}
217215

218-
module.exports = md5;
216+
module.exports = md5;

lib/md5.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
var crypto = require('crypto');
44

55
function md5(bytes) {
6-
// support modern Buffer API
7-
if (typeof Buffer.from === 'function') {
8-
if (Array.isArray(bytes)) bytes = Buffer.from(bytes);
9-
else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8');
10-
}
6+
if (typeof Buffer.from === 'function') {
7+
// Support modern Buffer API
8+
if (Array.isArray(bytes)) bytes = Buffer.from(bytes);
9+
else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8');
10+
} else {
11+
// Support pre-v4 Buffer API
12+
if (Array.isArray(bytes)) bytes = new Buffer(bytes);
13+
else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8');
14+
}
1115

12-
// support pre-v4 Buffer API
13-
else {
14-
if (Array.isArray(bytes)) bytes = new Buffer(bytes);
15-
else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8');
16-
}
17-
18-
return crypto.createHash('md5').update(bytes).digest();
16+
return crypto.createHash('md5').update(bytes).digest();
1917
}
2018

2119
module.exports = md5;

0 commit comments

Comments
 (0)