50c1875f by brandonocasey

code review fixes

1 parent 3c428e4b
...@@ -101,7 +101,7 @@ const precompute = function() { ...@@ -101,7 +101,7 @@ const precompute = function() {
101 decTable[i] = decTable[i].slice(0); 101 decTable[i] = decTable[i].slice(0);
102 } 102 }
103 return _tables; 103 return _tables;
104 } 104 };
105 105
106 let tables; 106 let tables;
107 107
...@@ -367,12 +367,11 @@ export class AsyncStream extends Stream { ...@@ -367,12 +367,11 @@ export class AsyncStream extends Stream {
367 } 367 }
368 368
369 // the maximum number of bytes to process at one time 369 // the maximum number of bytes to process at one time
370 const decrypterStep = 4 * 8000; 370 const DecrypterStep = 4 * 8000;
371 371
372 export class Decrypter extends Stream { 372 export class Decrypter {
373 constructor(encrypted, key, initVector, done) { 373 constructor(encrypted, key, initVector, done) {
374 super(Stream); 374 let step = DecrypterStep;
375 let step = decrypterStep;
376 let encrypted32 = new Int32Array(encrypted.buffer); 375 let encrypted32 = new Int32Array(encrypted.buffer);
377 let decrypted = new Uint8Array(encrypted.byteLength); 376 let decrypted = new Uint8Array(encrypted.byteLength);
378 let i = 0; 377 let i = 0;
...@@ -409,7 +408,7 @@ export class Decrypter extends Stream { ...@@ -409,7 +408,7 @@ export class Decrypter extends Stream {
409 } 408 }
410 } 409 }
411 410
412 Decrypter.STEP = decrypterStep; 411 Decrypter.STEP = DecrypterStep;
413 412
414 export default { 413 export default {
415 decrypt, 414 decrypt,
......
...@@ -106,24 +106,20 @@ QUnit.test('asynchronously decrypts a 4-word block', function() { ...@@ -106,24 +106,20 @@ QUnit.test('asynchronously decrypts a 4-word block', function() {
106 let key = new Uint32Array([0, 0, 0, 0]); 106 let key = new Uint32Array([0, 0, 0, 0]);
107 let initVector = key; 107 let initVector = key;
108 // the string "howdy folks" encrypted 108 // the string "howdy folks" encrypted
109 let encrypted = new Uint8Array([ 109 let encrypted = new Uint8Array([0xce, 0x90, 0x97, 0xd0,
110 0xce, 0x90, 0x97, 0xd0, 110 0x08, 0x46, 0x4d, 0x18,
111 0x08, 0x46, 0x4d, 0x18, 111 0x4f, 0xae, 0x01, 0x1c,
112 0x4f, 0xae, 0x01, 0x1c, 112 0x82, 0xa8, 0xf0, 0x67]);
113 0x82, 0xa8, 0xf0, 0x67
114 ]);
115 let decrypted; 113 let decrypted;
116 let decrypter = new Decrypter( 114 let decrypter = new Decrypter(encrypted,
117 encrypted, 115 key,
118 key, 116 initVector,
119 initVector, 117 function(error, result) {
120 function(error, result) { 118 if (error) {
121 if (error) { 119 throw new Error(error);
122 throw new Error(error); 120 }
123 } 121 decrypted = result;
124 decrypted = result; 122 });
125 }
126 );
127 123
128 QUnit.ok(!decrypted, 'asynchronously decrypts'); 124 QUnit.ok(!decrypted, 'asynchronously decrypts');
129 this.clock.tick(decrypter.asyncStream_.delay * 2); 125 this.clock.tick(decrypter.asyncStream_.delay * 2);
...@@ -137,14 +133,12 @@ QUnit.test('asynchronously decrypts a 4-word block', function() { ...@@ -137,14 +133,12 @@ QUnit.test('asynchronously decrypts a 4-word block', function() {
137 QUnit.test('breaks up input greater than the step value', function() { 133 QUnit.test('breaks up input greater than the step value', function() {
138 let encrypted = new Int32Array(Decrypter.STEP + 4); 134 let encrypted = new Int32Array(Decrypter.STEP + 4);
139 let done = false; 135 let done = false;
140 let decrypter = new Decrypter( 136 let decrypter = new Decrypter(encrypted,
141 encrypted, 137 new Uint32Array(4),
142 new Uint32Array(4), 138 new Uint32Array(4),
143 new Uint32Array(4), 139 function() {
144 function() { 140 done = true;
145 done = true; 141 });
146 }
147 );
148 142
149 this.clock.tick(decrypter.asyncStream_.delay * 2); 143 this.clock.tick(decrypter.asyncStream_.delay * 2);
150 QUnit.ok(!done, 'not finished after two ticks'); 144 QUnit.ok(!done, 'not finished after two ticks');
......