mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-11 11:15:00 +00:00
Fix armor errors
Also, fix error handling in transformPair()
This commit is contained in:
@@ -38,31 +38,35 @@ function List() {
|
||||
List.prototype.read = async function (bytes) {
|
||||
this.stream = stream.transformPair(bytes, async (readable, writable) => {
|
||||
const writer = stream.getWriter(writable);
|
||||
while (true) {
|
||||
await writer.ready;
|
||||
const done = await packetParser.read(readable, async parsed => {
|
||||
try {
|
||||
const tag = enums.read(enums.packet, parsed.tag);
|
||||
const packet = packets.newPacketFromTag(tag);
|
||||
packet.packets = new List();
|
||||
packet.fromStream = util.isStream(parsed.packet);
|
||||
await packet.read(parsed.packet);
|
||||
await writer.write(packet);
|
||||
} catch (e) {
|
||||
if (!config.tolerant ||
|
||||
parsed.tag === enums.packet.symmetricallyEncrypted ||
|
||||
parsed.tag === enums.packet.literal ||
|
||||
parsed.tag === enums.packet.compressed) {
|
||||
writer.abort(e);
|
||||
}
|
||||
util.print_debug_error(e);
|
||||
}
|
||||
});
|
||||
if (done) {
|
||||
try {
|
||||
while (true) {
|
||||
await writer.ready;
|
||||
writer.close();
|
||||
return;
|
||||
const done = await packetParser.read(readable, async parsed => {
|
||||
try {
|
||||
const tag = enums.read(enums.packet, parsed.tag);
|
||||
const packet = packets.newPacketFromTag(tag);
|
||||
packet.packets = new List();
|
||||
packet.fromStream = util.isStream(parsed.packet);
|
||||
await packet.read(parsed.packet);
|
||||
await writer.write(packet);
|
||||
} catch (e) {
|
||||
if (!config.tolerant ||
|
||||
parsed.tag === enums.packet.symmetricallyEncrypted ||
|
||||
parsed.tag === enums.packet.literal ||
|
||||
parsed.tag === enums.packet.compressed) {
|
||||
await writer.abort(e);
|
||||
}
|
||||
util.print_debug_error(e);
|
||||
}
|
||||
});
|
||||
if (done) {
|
||||
await writer.ready;
|
||||
await writer.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
await writer.abort(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -147,41 +147,45 @@ SymEncryptedAEADProtected.prototype.crypt = async function (fn, key, data) {
|
||||
return stream.transformPair(data, async (readable, writable) => {
|
||||
const reader = stream.getReader(readable);
|
||||
const writer = stream.getWriter(writable);
|
||||
while (true) {
|
||||
await writer.ready;
|
||||
let chunk = await reader.readBytes(chunkSize + tagLengthIfDecrypting) || new Uint8Array();
|
||||
const finalChunk = chunk.subarray(chunk.length - tagLengthIfDecrypting);
|
||||
chunk = chunk.subarray(0, chunk.length - tagLengthIfDecrypting);
|
||||
let cryptedPromise;
|
||||
let done;
|
||||
if (!chunkIndex || chunk.length) {
|
||||
reader.unshift(finalChunk);
|
||||
cryptedPromise = modeInstance[fn](chunk, mode.getNonce(iv, chunkIndexArray), adataArray);
|
||||
} else {
|
||||
// After the last chunk, we either encrypt a final, empty
|
||||
// data chunk to get the final authentication tag or
|
||||
// validate that final authentication tag.
|
||||
adataView.setInt32(13 + 4, cryptedBytes); // Should be setInt64(13, ...)
|
||||
cryptedPromise = modeInstance[fn](finalChunk, mode.getNonce(iv, chunkIndexArray), adataTagArray);
|
||||
done = true;
|
||||
}
|
||||
cryptedBytes += chunk.length - tagLengthIfDecrypting;
|
||||
queuedBytes += chunk.length - tagLengthIfDecrypting;
|
||||
// eslint-disable-next-line no-loop-func
|
||||
latestPromise = latestPromise.then(() => cryptedPromise).then(crypted => {
|
||||
writer.write(crypted);
|
||||
queuedBytes -= chunk.length;
|
||||
}).catch(err => writer.abort(err));
|
||||
// console.log(fn, done, queuedBytes, writer.desiredSize);
|
||||
if (done || queuedBytes > writer.desiredSize) {
|
||||
await latestPromise; // Respect backpressure
|
||||
}
|
||||
if (!done) {
|
||||
adataView.setInt32(5 + 4, ++chunkIndex); // Should be setInt64(5, ...)
|
||||
} else {
|
||||
writer.close();
|
||||
break;
|
||||
try {
|
||||
while (true) {
|
||||
await writer.ready;
|
||||
let chunk = await reader.readBytes(chunkSize + tagLengthIfDecrypting) || new Uint8Array();
|
||||
const finalChunk = chunk.subarray(chunk.length - tagLengthIfDecrypting);
|
||||
chunk = chunk.subarray(0, chunk.length - tagLengthIfDecrypting);
|
||||
let cryptedPromise;
|
||||
let done;
|
||||
if (!chunkIndex || chunk.length) {
|
||||
reader.unshift(finalChunk);
|
||||
cryptedPromise = modeInstance[fn](chunk, mode.getNonce(iv, chunkIndexArray), adataArray);
|
||||
} else {
|
||||
// After the last chunk, we either encrypt a final, empty
|
||||
// data chunk to get the final authentication tag or
|
||||
// validate that final authentication tag.
|
||||
adataView.setInt32(13 + 4, cryptedBytes); // Should be setInt64(13, ...)
|
||||
cryptedPromise = modeInstance[fn](finalChunk, mode.getNonce(iv, chunkIndexArray), adataTagArray);
|
||||
done = true;
|
||||
}
|
||||
cryptedBytes += chunk.length - tagLengthIfDecrypting;
|
||||
queuedBytes += chunk.length - tagLengthIfDecrypting;
|
||||
// eslint-disable-next-line no-loop-func
|
||||
latestPromise = latestPromise.then(() => cryptedPromise).then(async crypted => {
|
||||
await writer.write(crypted);
|
||||
queuedBytes -= chunk.length;
|
||||
}).catch(err => writer.abort(err));
|
||||
// console.log(fn, done, queuedBytes, writer.desiredSize);
|
||||
if (done || queuedBytes > writer.desiredSize) {
|
||||
await latestPromise; // Respect backpressure
|
||||
}
|
||||
if (!done) {
|
||||
adataView.setInt32(5 + 4, ++chunkIndex); // Should be setInt64(5, ...)
|
||||
} else {
|
||||
await writer.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
await writer.abort(e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user