meteor-node-stubs 1.2.22 → 1.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,80 @@
1
- var tape = require('tape')
2
- var Hash = require('../hash')
3
- var hex = '0A1B2C3D4E5F6G7H'
1
+ 'use strict';
4
2
 
5
- function equal (t, a, b) {
6
- t.equal(a.length, b.length)
7
- t.equal(a.toString('hex'), b.toString('hex'))
3
+ var tape = require('tape');
4
+ var Buffer = require('safe-buffer').Buffer;
5
+
6
+ var Hash = require('../hash');
7
+
8
+ var hex = '0A1B2C3D4E5F6G7H';
9
+
10
+ function equal(t, a, b) {
11
+ t.equal(a.length, b.length);
12
+ t.equal(a.toString('hex'), b.toString('hex'));
8
13
  }
9
14
 
10
- var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8')
15
+ var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8');
11
16
  var count16 = {
12
- strings: ['0A1B2C3D4E5F6G7H'],
13
- buffers: [
14
- hexBuf,
15
- Buffer.from('80000000000000000000000000000080', 'hex')
16
- ]
17
- }
17
+ strings: ['0A1B2C3D4E5F6G7H'],
18
+ buffers: [
19
+ hexBuf,
20
+ Buffer.from('80000000000000000000000000000080', 'hex')
21
+ ]
22
+ };
18
23
 
19
24
  var empty = {
20
- strings: [''],
21
- buffers: [
22
- Buffer.from('80000000000000000000000000000000', 'hex')
23
- ]
24
- }
25
+ strings: [''],
26
+ buffers: [
27
+ Buffer.from('80000000000000000000000000000000', 'hex')
28
+ ]
29
+ };
25
30
 
26
31
  var multi = {
27
- strings: ['abcd', 'efhijk', 'lmnopq'],
28
- buffers: [
29
- Buffer.from('abcdefhijklmnopq', 'ascii'),
30
- Buffer.from('80000000000000000000000000000080', 'hex')
31
- ]
32
- }
32
+ strings: ['abcd', 'efhijk', 'lmnopq'],
33
+ buffers: [
34
+ Buffer.from('abcdefhijklmnopq', 'ascii'),
35
+ Buffer.from('80000000000000000000000000000080', 'hex')
36
+ ]
37
+ };
33
38
 
34
39
  var long = {
35
- strings: [hex + hex],
36
- buffers: [
37
- hexBuf,
38
- hexBuf,
39
- Buffer.from('80000000000000000000000000000100', 'hex')
40
- ]
41
- }
40
+ strings: [hex + hex],
41
+ buffers: [
42
+ hexBuf,
43
+ hexBuf,
44
+ Buffer.from('80000000000000000000000000000100', 'hex')
45
+ ]
46
+ };
42
47
 
43
- function makeTest (name, data) {
44
- tape(name, function (t) {
45
- var h = new Hash(16, 8)
46
- var hash = Buffer.alloc(20)
47
- var n = 2
48
- var expected = data.buffers.slice()
49
- // t.plan(expected.length + 1)
48
+ function makeTest(name, data) {
49
+ tape(name, function (t) {
50
+ var h = new Hash(16, 8);
51
+ var hash = Buffer.alloc(20);
52
+ var n = 2;
53
+ var expected = data.buffers.slice();
54
+ // t.plan(expected.length + 1)
50
55
 
51
- h._update = function (block) {
52
- var e = expected.shift()
53
- equal(t, block, e)
56
+ h._update = function (block) {
57
+ var e = expected.shift();
58
+ equal(t, block, e);
54
59
 
55
- if (n < 0) {
56
- throw new Error('expecting only 2 calls to _update')
57
- }
58
- }
59
- h._hash = function () {
60
- return hash
61
- }
60
+ if (n < 0) {
61
+ throw new Error('expecting only 2 calls to _update');
62
+ }
63
+ };
64
+ h._hash = function () {
65
+ return hash;
66
+ };
62
67
 
63
- data.strings.forEach(function (string) {
64
- h.update(string, 'ascii')
65
- })
68
+ data.strings.forEach(function (string) {
69
+ h.update(string, 'ascii');
70
+ });
66
71
 
67
- equal(t, h.digest(), hash)
68
- t.end()
69
- })
72
+ equal(t, h.digest(), hash);
73
+ t.end();
74
+ });
70
75
  }
71
76
 
72
- makeTest('Hash#update 1 in 1', count16)
73
- makeTest('empty Hash#update', empty)
74
- makeTest('Hash#update 1 in 3', multi)
75
- makeTest('Hash#update 2 in 1', long)
77
+ makeTest('Hash#update 1 in 1', count16);
78
+ makeTest('empty Hash#update', empty);
79
+ makeTest('Hash#update 1 in 3', multi);
80
+ makeTest('Hash#update 2 in 1', long);
@@ -1,100 +1,138 @@
1
- var crypto = require('crypto')
2
- var tape = require('tape')
3
- var Sha1 = require('../').sha1
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var tape = require('tape');
5
+ var Buffer = require('safe-buffer').Buffer;
6
+
7
+ var Sha1 = require('../').sha1;
8
+
9
+ var nodeSupportsUint16 = false;
10
+ try {
11
+ crypto.createHash('sha1').update(new Uint16Array());
12
+ nodeSupportsUint16 = true;
13
+ } catch (err) {}
4
14
 
5
15
  var inputs = [
6
- ['', 'ascii'],
7
- ['abc', 'ascii'],
8
- ['123', 'ascii'],
9
- ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
10
- ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
11
- ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
12
- ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
13
- ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
14
- ['foobarbaz', 'ascii']
15
- ]
16
+ ['', 'ascii'],
17
+ ['abc', 'ascii'],
18
+ ['123', 'ascii'],
19
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
20
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
21
+ ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
22
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
23
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
24
+ ['foobarbaz', 'ascii'],
25
+ [Buffer.from('buffer')],
26
+ nodeSupportsUint16 ? [new Uint16Array([1, 2, 3])] : null
27
+ ].filter(Boolean);
16
28
 
17
29
  tape("hash is the same as node's crypto", function (t) {
18
- inputs.forEach(function (v) {
19
- var a = new Sha1().update(v[0], v[1]).digest('hex')
20
- var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex')
21
- console.log(a, '==', e)
22
- t.equal(a, e)
23
- })
30
+ inputs.forEach(function (v) {
31
+ var a = new Sha1().update(v[0], v[1]).digest('hex');
32
+ var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex');
33
+ t.equal(a, e, a + ' == ' + e);
34
+ });
24
35
 
25
- t.end()
26
- })
36
+ t.end();
37
+ });
27
38
 
28
39
  tape('call update multiple times', function (t) {
29
- inputs.forEach(function (v) {
30
- var hash = new Sha1()
31
- var _hash = crypto.createHash('sha1')
32
-
33
- for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
34
- var s = v[0].substring(i, (i + 1) * 2)
35
- hash.update(s, v[1])
36
- _hash.update(s, v[1])
37
- }
38
-
39
- var a = hash.digest('hex')
40
- var e = _hash.digest('hex')
41
- console.log(a, '==', e)
42
- t.equal(a, e)
43
- })
44
- t.end()
45
- })
40
+ inputs.forEach(function (v) {
41
+ var hash = new Sha1();
42
+ var sha1hash = crypto.createHash('sha1');
43
+
44
+ for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
45
+ var s = v[0].slice(i, (i + 1) * 2);
46
+ hash.update(s, v[1]);
47
+ sha1hash.update(s, v[1]);
48
+ }
49
+
50
+ var a = hash.digest('hex');
51
+ var e = sha1hash.digest('hex');
52
+ t.equal(a, e, a + ' == ' + e);
53
+ });
54
+ t.end();
55
+ });
46
56
 
47
57
  tape('call update twice', function (t) {
48
- var _hash = crypto.createHash('sha1')
49
- var hash = new Sha1()
58
+ var sha1hash = crypto.createHash('sha1');
59
+ var hash = new Sha1();
50
60
 
51
- _hash.update('foo', 'ascii')
52
- hash.update('foo', 'ascii')
61
+ sha1hash.update('foo', 'ascii');
62
+ hash.update('foo', 'ascii');
53
63
 
54
- _hash.update('bar', 'ascii')
55
- hash.update('bar', 'ascii')
64
+ sha1hash.update('bar', 'ascii');
65
+ hash.update('bar', 'ascii');
56
66
 
57
- _hash.update('baz', 'ascii')
58
- hash.update('baz', 'ascii')
67
+ sha1hash.update('baz', 'ascii');
68
+ hash.update('baz', 'ascii');
59
69
 
60
- var a = hash.digest('hex')
61
- var e = _hash.digest('hex')
70
+ var a = hash.digest('hex');
71
+ var e = sha1hash.digest('hex');
62
72
 
63
- t.equal(a, e)
64
- t.end()
65
- })
73
+ t.equal(a, e);
74
+ t.end();
75
+ });
66
76
 
67
77
  tape('hex encoding', function (t) {
68
- inputs.forEach(function (v) {
69
- var hash = new Sha1()
70
- var _hash = crypto.createHash('sha1')
71
-
72
- for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
73
- var s = v[0].substring(i, (i + 1) * 2)
74
- hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
75
- _hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
76
- }
77
- var a = hash.digest('hex')
78
- var e = _hash.digest('hex')
79
-
80
- console.log(a, '==', e)
81
- t.equal(a, e)
82
- })
83
-
84
- t.end()
85
- })
78
+ inputs.forEach(function (v) {
79
+ var hash = new Sha1();
80
+ var sha1hash = crypto.createHash('sha1');
81
+
82
+ for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
83
+ var s = v[0].slice(i, (i + 1) * 2);
84
+ hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex');
85
+ sha1hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex');
86
+ }
87
+ var a = hash.digest('hex');
88
+ var e = sha1hash.digest('hex');
89
+
90
+ t.equal(a, e, a + ' == ' + e);
91
+ });
92
+
93
+ t.end();
94
+ });
95
+
96
+ tape('throws on invalid input', function (t) {
97
+ var invalid = [
98
+ {}, // non-arrayish
99
+ { length: 20 }, // undefined values
100
+ [NaN], // non-numbers
101
+ [[]], // non-numbers
102
+ [1, 1.5], // non-integers
103
+ [1, 256], // out of bounds
104
+ [-1, 0] // out of bounds
105
+ ];
106
+
107
+ invalid.forEach(function (input) {
108
+ var hash = new Sha1();
109
+
110
+ t['throws'](function () {
111
+ hash.update(input);
112
+ hash.digest('hex');
113
+ });
114
+ });
115
+
116
+ t.end();
117
+ });
86
118
 
87
119
  tape('call digest for more than MAX_UINT32 bits of data', function (t) {
88
- var _hash = crypto.createHash('sha1')
89
- var hash = new Sha1()
90
- var bigData = Buffer.alloc(0x1ffffffff / 8)
91
-
92
- hash.update(bigData)
93
- _hash.update(bigData)
94
-
95
- var a = hash.digest('hex')
96
- var e = _hash.digest('hex')
97
-
98
- t.equal(a, e)
99
- t.end()
100
- })
120
+ var sha1hash = crypto.createHash('sha1');
121
+ var hash = new Sha1();
122
+ var bigData;
123
+ try {
124
+ bigData = Buffer.alloc(0x1ffffffff / 8);
125
+ } catch (err) {
126
+ // node < 3 has a lower buffer size limit than node 3+. node 0.10 requires the `/8`, 0.12 - 2 are fine with `-8`
127
+ bigData = Buffer.alloc(0x3fffffff / 8);
128
+ }
129
+
130
+ hash.update(bigData);
131
+ sha1hash.update(bigData);
132
+
133
+ var a = hash.digest('hex');
134
+ var e = sha1hash.digest('hex');
135
+
136
+ t.equal(a, e, a + ' == ' + e);
137
+ t.end();
138
+ });
@@ -1,72 +1,72 @@
1
- var tape = require('tape')
2
- var vectors = require('hash-test-vectors')
1
+ 'use strict';
2
+
3
+ var tape = require('tape');
4
+ var vectors = require('hash-test-vectors');
3
5
  // var from = require('bops/typedarray/from')
4
- var Buffer = require('safe-buffer').Buffer
6
+ var Buffer = require('safe-buffer').Buffer;
5
7
 
6
- var createHash = require('../')
8
+ var createHash = require('../');
7
9
 
8
- function makeTest (alg, i, verbose) {
9
- var v = vectors[i]
10
+ function makeTest(alg, i, verbose) {
11
+ var v = vectors[i];
10
12
 
11
- tape(alg + ': NIST vector ' + i, function (t) {
12
- if (verbose) {
13
- console.log(v)
14
- console.log('VECTOR', i)
15
- console.log('INPUT', v.input)
16
- console.log(Buffer.from(v.input, 'base64').toString('hex'))
17
- }
13
+ tape(alg + ': NIST vector ' + i, function (t) {
14
+ if (verbose) {
15
+ t.comment(v);
16
+ t.comment('VECTOR', i);
17
+ t.comment('INPUT', v.input);
18
+ t.comment(Buffer.from(v.input, 'base64').toString('hex'));
19
+ }
18
20
 
19
- var buf = Buffer.from(v.input, 'base64')
20
- t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
21
+ var buf = Buffer.from(v.input, 'base64');
22
+ t.equal(createHash(alg).update(buf).digest('hex'), v[alg]);
21
23
 
22
- i = ~~(buf.length / 2)
23
- var buf1 = buf.slice(0, i)
24
- var buf2 = buf.slice(i, buf.length)
24
+ // eslint-disable-next-line no-param-reassign
25
+ i = ~~(buf.length / 2);
26
+ var buf1 = buf.slice(0, i);
27
+ var buf2 = buf.slice(i, buf.length);
25
28
 
26
- console.log(buf1.length, buf2.length, buf.length)
27
- console.log(createHash(alg)._block.length)
29
+ t.comment(buf1.length + ', ' + buf2.length + ', ' + buf.length);
30
+ t.comment(createHash(alg)._block.length);
28
31
 
29
- t.equal(
30
- createHash(alg)
31
- .update(buf1)
32
- .update(buf2)
33
- .digest('hex'),
34
- v[alg]
35
- )
32
+ t.equal(
33
+ createHash(alg)
34
+ .update(buf1)
35
+ .update(buf2)
36
+ .digest('hex'),
37
+ v[alg]
38
+ );
36
39
 
37
- var j, buf3
40
+ var j, buf3;
38
41
 
39
- i = ~~(buf.length / 3)
40
- j = ~~(buf.length * 2 / 3)
41
- buf1 = buf.slice(0, i)
42
- buf2 = buf.slice(i, j)
43
- buf3 = buf.slice(j, buf.length)
42
+ // eslint-disable-next-line no-param-reassign
43
+ i = ~~(buf.length / 3);
44
+ j = ~~(buf.length * 2 / 3);
45
+ buf1 = buf.slice(0, i);
46
+ buf2 = buf.slice(i, j);
47
+ buf3 = buf.slice(j, buf.length);
44
48
 
45
- t.equal(
46
- createHash(alg)
47
- .update(buf1)
48
- .update(buf2)
49
- .update(buf3)
50
- .digest('hex'),
51
- v[alg]
52
- )
49
+ t.equal(
50
+ createHash(alg)
51
+ .update(buf1)
52
+ .update(buf2)
53
+ .update(buf3)
54
+ .digest('hex'),
55
+ v[alg]
56
+ );
53
57
 
54
- setTimeout(function () {
55
- // avoid "too much recursion" errors in tape in firefox
56
- t.end()
57
- })
58
- })
58
+ setTimeout(function () {
59
+ // avoid "too much recursion" errors in tape in firefox
60
+ t.end();
61
+ });
62
+ });
59
63
  }
60
64
 
61
- if (process.argv[2]) {
62
- makeTest(process.argv[2], parseInt(process.argv[3], 10), true)
63
- } else {
64
- vectors.forEach(function (v, i) {
65
- makeTest('sha', i)
66
- makeTest('sha1', i)
67
- makeTest('sha224', i)
68
- makeTest('sha256', i)
69
- makeTest('sha384', i)
70
- makeTest('sha512', i)
71
- })
72
- }
65
+ vectors.forEach(function (v, i) {
66
+ makeTest('sha', i);
67
+ makeTest('sha1', i);
68
+ makeTest('sha224', i);
69
+ makeTest('sha256', i);
70
+ makeTest('sha384', i);
71
+ makeTest('sha512', i);
72
+ });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "meteor-node-stubs",
3
3
  "author": "Ben Newman <ben@meteor.com>",
4
4
  "description": "Stub implementations of Node built-in modules, a la Browserify",
5
- "version": "1.2.22",
5
+ "version": "1.2.23",
6
6
  "main": "index.js",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/meteor/meteor/blob/devel/npm-packages/meteor-node-stubs/README.md",
@@ -18,6 +18,7 @@
18
18
  "console-browserify": "^1.2.0",
19
19
  "constants-browserify": "^1.0.0",
20
20
  "domain-browser": "^4.23.0",
21
+ "elliptic": "^6.6.1",
21
22
  "events": "^3.3.0",
22
23
  "https-browserify": "^1.0.0",
23
24
  "os-browserify": "^0.3.0",
@@ -26,6 +27,7 @@
26
27
  "punycode": "^1.4.1",
27
28
  "querystring-es3": "^0.2.1",
28
29
  "readable-stream": "^3.6.2",
30
+ "sha.js": "^2.4.12",
29
31
  "stream-browserify": "^3.0.0",
30
32
  "stream-http": "^3.2.0",
31
33
  "string_decoder": "^1.3.0",
@@ -1,17 +0,0 @@
1
- sudo: false
2
- os:
3
- - linux
4
- language: node_js
5
- node_js:
6
- - "4"
7
- - "5"
8
- - "6"
9
- - "7"
10
- env:
11
- matrix:
12
- - TEST_SUITE=unit
13
- matrix:
14
- include:
15
- - node_js: "7"
16
- env: TEST_SUITE=lint
17
- script: npm run $TEST_SUITE