[eslint] switch to eslint · browserify/sha.js@7acadfb
1-var Buffer = require('safe-buffer').Buffer
1+'use strict';
2+3+var Buffer = require('safe-buffer').Buffer;
2435// prototype class for hash functions
4-function Hash (blockSize, finalSize) {
5- this._block = Buffer.alloc(blockSize)
6- this._finalSize = finalSize
7- this._blockSize = blockSize
8- this._len = 0
6+function Hash(blockSize, finalSize) {
7+ this._block = Buffer.alloc(blockSize);
8+ this._finalSize = finalSize;
9+ this._blockSize = blockSize;
10+ this._len = 0;
911}
10121113Hash.prototype.update = function (data, enc) {
12-if (typeof data === 'string') {
13-enc = enc || 'utf8'
14-data = Buffer.from(data, enc)
15-}
16-17-var block = this._block
18-var blockSize = this._blockSize
19-var length = data.length
20-var accum = this._len
21-22-for (var offset = 0; offset < length;) {
23-var assigned = accum % blockSize
24-var remainder = Math.min(length - offset, blockSize - assigned)
25-26-for (var i = 0; i < remainder; i++) {
27-block[assigned + i] = data[offset + i]
28-}
29-30-accum += remainder
31-offset += remainder
32-33-if ((accum % blockSize) === 0) {
34-this._update(block)
35-}
36-}
37-38-this._len += length
39-return this
40-}
14+/* eslint no-param-reassign: 0 */
15+if (typeof data === 'string') {
16+enc = enc || 'utf8';
17+data = Buffer.from(data, enc);
18+}
19+20+var block = this._block;
21+var blockSize = this._blockSize;
22+var length = data.length;
23+var accum = this._len;
24+25+for (var offset = 0; offset < length;) {
26+var assigned = accum % blockSize;
27+var remainder = Math.min(length - offset, blockSize - assigned);
28+29+for (var i = 0; i < remainder; i++) {
30+block[assigned + i] = data[offset + i];
31+}
32+33+accum += remainder;
34+offset += remainder;
35+36+if ((accum % blockSize) === 0) {
37+this._update(block);
38+}
39+}
40+41+this._len += length;
42+return this;
43+};
41444245Hash.prototype.digest = function (enc) {
43- var rem = this._len % this._blockSize
46+ var rem = this._len % this._blockSize;
444745- this._block[rem] = 0x80
48+ this._block[rem] = 0x80;
464947-// zero (rem + 1) trailing bits, where (rem + 1) is the smallest
48-// non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
49-this._block.fill(0, rem + 1)
50+/*
51+ * zero (rem + 1) trailing bits, where (rem + 1) is the smallest
52+ * non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
53+ */
54+this._block.fill(0, rem + 1);
505551- if (rem >= this._finalSize) {
52- this._update(this._block)
53- this._block.fill(0)
54- }
56+ if (rem >= this._finalSize) {
57+ this._update(this._block);
58+ this._block.fill(0);
59+ }
556056- var bits = this._len * 8
61+ var bits = this._len * 8;
576258- // uint32
59- if (bits <= 0xffffffff) {
60- this._block.writeUInt32BE(bits, this._blockSize - 4)
63+ // uint32
64+ if (bits <= 0xffffffff) {
65+ this._block.writeUInt32BE(bits, this._blockSize - 4);
616662- // uint64
63- } else {
64- var lowBits = (bits & 0xffffffff) >>> 0
65- var highBits = (bits - lowBits) / 0x100000000
67+ // uint64
68+ } else {
69+ var lowBits = (bits & 0xffffffff) >>> 0;
70+ var highBits = (bits - lowBits) / 0x100000000;
667167- this._block.writeUInt32BE(highBits, this._blockSize - 8)
68- this._block.writeUInt32BE(lowBits, this._blockSize - 4)
69- }
72+ this._block.writeUInt32BE(highBits, this._blockSize - 8);
73+ this._block.writeUInt32BE(lowBits, this._blockSize - 4);
74+ }
707571- this._update(this._block)
72- var hash = this._hash()
76+ this._update(this._block);
77+ var hash = this._hash();
737874- return enc ? hash.toString(enc) : hash
75-}
79+ return enc ? hash.toString(enc) : hash;
80+};
76817782Hash.prototype._update = function () {
78- throw new Error('_update must be implemented by subclass')
79-}
83+ throw new Error('_update must be implemented by subclass');
84+};
808581-module.exports = Hash
86+module.exports = Hash;