Fix uncaught error in AttachmentCrypto

This commit is contained in:
Fedor Indutny
2025-10-29 12:39:37 -07:00
committed by GitHub
parent 363aff5330
commit 06448ea80e
4 changed files with 20 additions and 18 deletions

View File

@@ -387,17 +387,6 @@ export async function decryptAttachmentV2ToSink(
const hmac = createHmac(HashType.size256, macKey);
const plaintextHash = createHash(HashType.size256);
const incrementalDigestValidator =
options.type === 'standard' &&
options.theirIncrementalMac &&
options.theirChunkSize
? new ValidatingPassThrough(
Buffer.from(macKey),
everyNthByte(options.theirChunkSize),
Buffer.from(options.theirIncrementalMac)
)
: undefined;
let theirMac: Uint8Array | undefined;
// When downloading from backup there is an outer encryption layer; in that case we
@@ -436,6 +425,19 @@ export async function decryptAttachmentV2ToSink(
throw missingCaseError(options);
}
// Initializing `ValidatingPassThrough` might throw on invalid parameters so
// it is important to do it within `try {} catch {}`
const incrementalDigestValidator =
options.type === 'standard' &&
options.theirIncrementalMac &&
options.theirChunkSize
? new ValidatingPassThrough(
Buffer.from(macKey),
everyNthByte(options.theirChunkSize),
Buffer.from(options.theirIncrementalMac)
)
: undefined;
await pipeline(
[
ciphertextStream,