Fix check in MessageReceiver

This commit is contained in:
Fedor Indutny 2023-05-04 08:09:49 -07:00 committed by Josh Perez
parent 4bc81fd51a
commit 34baa0fa2f

View file

@ -159,6 +159,7 @@ type DecryptResult = Readonly<
type DecryptSealedSenderResult = Readonly<{ type DecryptSealedSenderResult = Readonly<{
plaintext?: Uint8Array; plaintext?: Uint8Array;
unsealedPlaintext?: SealedSenderDecryptionResult; unsealedPlaintext?: SealedSenderDecryptionResult;
wasEncrypted: boolean;
}>; }>;
type InnerDecryptResultType = Readonly<{ type InnerDecryptResultType = Readonly<{
@ -1700,6 +1701,7 @@ export default class MessageReceiver
return { return {
plaintext: plaintextContent.body(), plaintext: plaintextContent.body(),
wasEncrypted: false,
}; };
} }
@ -1731,7 +1733,7 @@ export default class MessageReceiver
), ),
zone zone
); );
return { plaintext }; return { plaintext, wasEncrypted: true };
} }
log.info( log.info(
@ -1773,7 +1775,7 @@ export default class MessageReceiver
zone zone
); );
return { unsealedPlaintext }; return { unsealedPlaintext, wasEncrypted: true };
} }
private async innerDecrypt( private async innerDecrypt(
@ -1892,14 +1894,11 @@ export default class MessageReceiver
} }
if (envelope.type === envelopeTypeEnum.UNIDENTIFIED_SENDER) { if (envelope.type === envelopeTypeEnum.UNIDENTIFIED_SENDER) {
log.info(`decrypt/${logId}: unidentified message`); log.info(`decrypt/${logId}: unidentified message`);
const { plaintext, unsealedPlaintext } = await this.decryptSealedSender( const { plaintext, unsealedPlaintext, wasEncrypted } =
stores, await this.decryptSealedSender(stores, envelope, ciphertext);
envelope,
ciphertext
);
if (plaintext) { if (plaintext) {
return { plaintext: this.unpad(plaintext), wasEncrypted: false }; return { plaintext: this.unpad(plaintext), wasEncrypted };
} }
if (unsealedPlaintext) { if (unsealedPlaintext) {
@ -1913,7 +1912,7 @@ export default class MessageReceiver
// Return just the content because that matches the signature of the other // Return just the content because that matches the signature of the other
// decrypt methods used above. // decrypt methods used above.
return { plaintext: this.unpad(content), wasEncrypted: true }; return { plaintext: this.unpad(content), wasEncrypted };
} }
throw new Error('Unexpected lack of plaintext from unidentified sender'); throw new Error('Unexpected lack of plaintext from unidentified sender');