Comments & code style

This commit is contained in:
Daniel Huigens
2018-07-05 13:44:33 +02:00
parent 1101a05b10
commit ca537e439d
21 changed files with 354 additions and 171 deletions

View File

@@ -182,15 +182,15 @@ describe('Streaming', function() {
canceled = true;
}
});
const encrypted = await openpgp.sign({
const signed = await openpgp.sign({
message: openpgp.message.fromBinary(data),
privateKeys: privKey
});
const reader = openpgp.stream.getReader(encrypted.data);
const reader = openpgp.stream.getReader(signed.data);
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
if (i > 10) throw new Error('Data did not arrive early.');
reader.releaseLock();
await openpgp.stream.cancel(encrypted.data);
await openpgp.stream.cancel(signed.data);
expect(canceled).to.be.true;
});
@@ -476,25 +476,25 @@ describe('Streaming', function() {
}
}
});
const encrypted = await openpgp.sign({
const signed = await openpgp.sign({
message: openpgp.message.fromBinary(data),
privateKeys: privKey
});
const msgAsciiArmored = encrypted.data;
const msgAsciiArmored = signed.data;
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
if (value.length > 1000) return value.slice(0, 499) + 'a' + value.slice(500);
return value;
}));
const decrypted = await openpgp.verify({
const verified = await openpgp.verify({
publicKeys: pubKey,
message
});
expect(util.isStream(decrypted.data)).to.be.true;
expect(await openpgp.stream.getReader(openpgp.stream.clone(decrypted.data)).readBytes(10)).not.to.deep.equal(plaintext[0]);
expect(util.isStream(verified.data)).to.be.true;
expect(await openpgp.stream.getReader(openpgp.stream.clone(verified.data)).readBytes(10)).not.to.deep.equal(plaintext[0]);
if (i > 10) throw new Error('Data did not arrive early.');
await expect(openpgp.stream.readToEnd(decrypted.data)).to.be.rejectedWith('Ascii armor integrity check on message failed');
expect(decrypted.signatures).to.exist.and.have.length(1);
await expect(openpgp.stream.readToEnd(verified.data)).to.be.rejectedWith('Ascii armor integrity check on message failed');
expect(verified.signatures).to.exist.and.have.length(1);
} finally {
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
}
@@ -702,26 +702,26 @@ describe('Streaming', function() {
canceled = true;
}
});
const encrypted = await openpgp.sign({
const signed = await openpgp.sign({
message: openpgp.message.fromBinary(data),
privateKeys: privKey
});
const msgAsciiArmored = encrypted.data;
const msgAsciiArmored = signed.data;
const message = await openpgp.message.readArmored(msgAsciiArmored);
const decrypted = await openpgp.verify({
const verified = await openpgp.verify({
publicKeys: pubKey,
message
});
expect(util.isStream(decrypted.data)).to.be.true;
const reader = openpgp.stream.getReader(decrypted.data);
expect(util.isStream(verified.data)).to.be.true;
const reader = openpgp.stream.getReader(verified.data);
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
if (i > 10) throw new Error('Data did not arrive early.');
reader.releaseLock();
await openpgp.stream.cancel(decrypted.data, new Error('canceled by test'));
await openpgp.stream.cancel(verified.data, new Error('canceled by test'));
expect(canceled).to.be.true;
expect(decrypted.signatures).to.exist.and.have.length(1);
expect(await decrypted.signatures[0].verified).to.be.undefined;
expect(verified.signatures).to.exist.and.have.length(1);
expect(await verified.signatures[0].verified).to.be.undefined;
} finally {
openpgp.config.aead_protect = aead_protectValue;
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
@@ -773,11 +773,11 @@ describe('Streaming', function() {
await new Promise(setTimeout);
}
});
const encrypted = await openpgp.sign({
const signed = await openpgp.sign({
message: openpgp.message.fromBinary(data),
privateKeys: privKey
});
const reader = openpgp.stream.getReader(encrypted.data);
const reader = openpgp.stream.getReader(signed.data);
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
if (i > 10) throw new Error('Data did not arrive early.');
await new Promise(resolve => setTimeout(resolve, 3000));
@@ -851,18 +851,18 @@ describe('Streaming', function() {
await new Promise(setTimeout);
}
});
const encrypted = await openpgp.sign({
const signed = await openpgp.sign({
message: openpgp.message.fromBinary(data),
privateKeys: privKey
});
const msgAsciiArmored = encrypted.data;
const msgAsciiArmored = signed.data;
const message = await openpgp.message.readArmored(msgAsciiArmored);
const decrypted = await openpgp.verify({
const verified = await openpgp.verify({
publicKeys: pubKey,
message
});
expect(util.isStream(decrypted.data)).to.be.true;
const reader = openpgp.stream.getReader(decrypted.data);
expect(util.isStream(verified.data)).to.be.true;
const reader = openpgp.stream.getReader(verified.data);
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
if (i > 10) throw new Error('Data did not arrive early.');
await new Promise(resolve => setTimeout(resolve, 3000));