envelopeTypeToCiphertextType: Handle all envelope types

This commit is contained in:
Scott Nonnenberg 2022-02-22 12:32:25 -08:00 committed by GitHub
parent 811e38b633
commit a1639f111e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -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}`);
}