From dd12c6f599c517224077fde7814f5b13567c4478 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:04:18 -0800 Subject: [PATCH] envelopeTypeToCiphertextType: Handle all envelope types Co-authored-by: Scott Nonnenberg --- ts/textsecure/MessageReceiver.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 67dd9a328..1fae2e88f 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -2792,14 +2792,35 @@ export default class MessageReceiver } function envelopeTypeToCiphertextType(type: number | undefined): number { - if (type === Proto.Envelope.Type.CIPHERTEXT) { + const { Type } = Proto.Envelope; + + if (type === Type.CIPHERTEXT) { return CiphertextMessageType.Whisper; } - if (type === Proto.Envelope.Type.PLAINTEXT_CONTENT) { + if (type === Type.KEY_EXCHANGE) { + throw new Error( + 'envelopeTypeToCiphertextType: Cannot process KEY_EXCHANGE messages' + ); + } + if (type === Type.PLAINTEXT_CONTENT) { return CiphertextMessageType.Plaintext; } - if (type === Proto.Envelope.Type.PREKEY_BUNDLE) { + if (type === Type.PREKEY_BUNDLE) { return CiphertextMessageType.PreKey; } + if (type === Type.RECEIPT) { + return CiphertextMessageType.Plaintext; + } + if (type === Type.UNIDENTIFIED_SENDER) { + throw new Error( + 'envelopeTypeToCiphertextType: Cannot process UNIDENTIFIED_SENDER messages' + ); + } + if (type === Type.UNKNOWN) { + throw new Error( + 'envelopeTypeToCiphertextType: Cannot process UNKNOWN messages' + ); + } + throw new Error(`envelopeTypeToCiphertextType: Unknown type ${type}`); }