added unsafe and safe events instead of console logging when a checksum is tampered with
This commit is contained in:
parent
5dd5743871
commit
89bc51c821
|
@ -91,20 +91,21 @@ class FileReceiver extends EventEmitter {
|
||||||
this.emit('hashing', false);
|
this.emit('hashing', false);
|
||||||
const integrity = new Uint8Array(calculatedHash).toString() === proposedHash.toString();
|
const integrity = new Uint8Array(calculatedHash).toString() === proposedHash.toString();
|
||||||
if (!integrity) {
|
if (!integrity) {
|
||||||
|
this.emit('unsafe', true)
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log('This file has been tampered with.')
|
|
||||||
reject();
|
reject();
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
this.emit('safe', true);
|
||||||
|
return Promise.all([
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
resolve(decrypted);
|
||||||
|
}),
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
resolve(fname);
|
||||||
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all([
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
resolve(decrypted);
|
|
||||||
}),
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
resolve(fname);
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,6 +235,10 @@ describe('File Receiver', function() {
|
||||||
testDecrypting = isStillDecrypting;
|
testDecrypting = isStillDecrypting;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fr.on('safe', isSafe => {
|
||||||
|
assert(isSafe);
|
||||||
|
})
|
||||||
|
|
||||||
return fr.download().then(([decrypted, name]) => {
|
return fr.download().then(([decrypted, name]) => {
|
||||||
assert(decrypted);
|
assert(decrypted);
|
||||||
assert(name);
|
assert(name);
|
||||||
|
@ -256,6 +260,10 @@ describe('File Receiver', function() {
|
||||||
testHashing = isStillHashing;
|
testHashing = isStillHashing;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fr.on('safe', isSafe => {
|
||||||
|
assert(isSafe);
|
||||||
|
})
|
||||||
|
|
||||||
return fr.download().then(([decrypted, name]) => {
|
return fr.download().then(([decrypted, name]) => {
|
||||||
assert(decrypted);
|
assert(decrypted);
|
||||||
assert(name);
|
assert(name);
|
||||||
|
@ -305,6 +313,10 @@ describe('File Receiver', function() {
|
||||||
const fr = new FileReceiver();
|
const fr = new FileReceiver();
|
||||||
location.hash = secretKey;
|
location.hash = secretKey;
|
||||||
|
|
||||||
|
fr.on('unsafe', isUnsafe => {
|
||||||
|
assert(isUnsafe)
|
||||||
|
})
|
||||||
|
|
||||||
fr.download().then(() => {
|
fr.download().then(() => {
|
||||||
assert.fail();
|
assert.fail();
|
||||||
done();
|
done();
|
||||||
|
|
Loading…
Reference in New Issue