50c1875f by brandonocasey

code review fixes

1 parent 3c428e4b
......@@ -101,7 +101,7 @@ const precompute = function() {
decTable[i] = decTable[i].slice(0);
}
return _tables;
}
};
let tables;
......@@ -367,12 +367,11 @@ export class AsyncStream extends Stream {
}
// the maximum number of bytes to process at one time
const decrypterStep = 4 * 8000;
const DecrypterStep = 4 * 8000;
export class Decrypter extends Stream {
export class Decrypter {
constructor(encrypted, key, initVector, done) {
super(Stream);
let step = decrypterStep;
let step = DecrypterStep;
let encrypted32 = new Int32Array(encrypted.buffer);
let decrypted = new Uint8Array(encrypted.byteLength);
let i = 0;
......@@ -409,7 +408,7 @@ export class Decrypter extends Stream {
}
}
Decrypter.STEP = decrypterStep;
Decrypter.STEP = DecrypterStep;
export default {
decrypt,
......
......@@ -106,24 +106,20 @@ QUnit.test('asynchronously decrypts a 4-word block', function() {
let key = new Uint32Array([0, 0, 0, 0]);
let initVector = key;
// the string "howdy folks" encrypted
let encrypted = new Uint8Array([
0xce, 0x90, 0x97, 0xd0,
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67
]);
let encrypted = new Uint8Array([0xce, 0x90, 0x97, 0xd0,
0x08, 0x46, 0x4d, 0x18,
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67]);
let decrypted;
let decrypter = new Decrypter(
encrypted,
key,
initVector,
function(error, result) {
if (error) {
throw new Error(error);
}
decrypted = result;
}
);
let decrypter = new Decrypter(encrypted,
key,
initVector,
function(error, result) {
if (error) {
throw new Error(error);
}
decrypted = result;
});
QUnit.ok(!decrypted, 'asynchronously decrypts');
this.clock.tick(decrypter.asyncStream_.delay * 2);
......@@ -137,14 +133,12 @@ QUnit.test('asynchronously decrypts a 4-word block', function() {
QUnit.test('breaks up input greater than the step value', function() {
let encrypted = new Int32Array(Decrypter.STEP + 4);
let done = false;
let decrypter = new Decrypter(
encrypted,
new Uint32Array(4),
new Uint32Array(4),
function() {
done = true;
}
);
let decrypter = new Decrypter(encrypted,
new Uint32Array(4),
new Uint32Array(4),
function() {
done = true;
});
this.clock.tick(decrypter.asyncStream_.delay * 2);
QUnit.ok(!done, 'not finished after two ticks');
......