From 154a169ffbc3b8bdca55588b2dcb1ba620a29120 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Fri, 10 Jul 2020 14:00:58 +0100 Subject: [PATCH] Moved message.ContentType base checks to a switch --- protocol/message_validator.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/protocol/message_validator.go b/protocol/message_validator.go index 67b4a6a35..031445a83 100644 --- a/protocol/message_validator.go +++ b/protocol/message_validator.go @@ -167,19 +167,18 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp return errors.New("chatId can't be empty") } - if message.ContentType == protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE { - return errors.New("unknown content type") - } - - if message.ContentType == protobuf.ChatMessage_TRANSACTION_COMMAND { - return errors.New("can't receive request address for transaction from others") - } - if message.MessageType == protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP { return errors.New("unknown message type") } - if message.ContentType == protobuf.ChatMessage_STICKER { + switch message.ContentType { + case protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE: + return errors.New("unknown content type") + + case protobuf.ChatMessage_TRANSACTION_COMMAND: + return errors.New("can't receive request address for transaction from others") + + case protobuf.ChatMessage_STICKER: if message.Payload == nil { return errors.New("no sticker content") } @@ -190,9 +189,8 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp if len(sticker.Hash) == 0 { return errors.New("sticker hash not set") } - } - if message.ContentType == protobuf.ChatMessage_IMAGE { + case protobuf.ChatMessage_IMAGE: if message.Payload == nil { return errors.New("no image content") } @@ -203,7 +201,6 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp if len(image.Payload) == 0 { return errors.New("image payload empty") } - if image.Type == protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE { return errors.New("image type unknown") }