Reject signatures[*].verified and signatures[*].signature on read errors
However, don't throw "unhandled promise rejection" when not using these properties at all, or when they reject before the user has a chance to handle them.
This commit is contained in:
parent
c3419e5cd0
commit
9c82bf491e
|
@ -549,8 +549,9 @@ Message.prototype.verify = async function(keys, date=new Date(), streaming) {
|
|||
const signatureList = msg.packets.filterByTag(enums.packet.signature);
|
||||
if (onePassSigList.length && !signatureList.length && msg.packets.stream) {
|
||||
onePassSigList.forEach(onePassSig => {
|
||||
onePassSig.correspondingSig = new Promise(resolve => {
|
||||
onePassSig.correspondingSig = new Promise((resolve, reject) => {
|
||||
onePassSig.correspondingSigResolve = resolve;
|
||||
onePassSig.correspondingSigReject = reject;
|
||||
});
|
||||
onePassSig.signatureData = stream.fromAsync(async () => (await onePassSig.correspondingSig).signatureData);
|
||||
onePassSig.hashed = onePassSig.hash(literalDataList[0], undefined, streaming);
|
||||
|
@ -568,10 +569,7 @@ Message.prototype.verify = async function(keys, date=new Date(), streaming) {
|
|||
await writer.close();
|
||||
} catch(e) {
|
||||
onePassSigList.forEach(onePassSig => {
|
||||
onePassSig.correspondingSigResolve({
|
||||
tag: enums.packet.signature,
|
||||
verify: () => undefined
|
||||
});
|
||||
onePassSig.correspondingSigReject(e);
|
||||
});
|
||||
await writer.abort(e);
|
||||
}
|
||||
|
@ -631,6 +629,13 @@ async function createVerificationObject(signature, literalDataList, keys, date=n
|
|||
return new Signature(packetlist);
|
||||
});
|
||||
|
||||
// Mark potential promise rejections as "handled". This is needed because in
|
||||
// some cases, we reject them before the user has a reasonable chance to
|
||||
// handle them (e.g. `await readToEnd(result.data); await result.verified` and
|
||||
// the data stream errors).
|
||||
verifiedSig.signature.catch(() => {});
|
||||
verifiedSig.verified.catch(() => {});
|
||||
|
||||
return verifiedSig;
|
||||
}
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ function tests() {
|
|||
await openpgp.stream.cancel(verified.data, new Error('canceled by test'));
|
||||
expect(canceled).to.be.true;
|
||||
expect(verified.signatures).to.exist.and.have.length(1);
|
||||
expect(await verified.signatures[0].verified).to.be.undefined;
|
||||
await expect(verified.signatures[0].verified).to.be.rejectedWith('canceled');
|
||||
} finally {
|
||||
openpgp.config.aead_protect = aead_protectValue;
|
||||
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
|
||||
|
|
Loading…
Reference in New Issue
Block a user