From 8879ef3f023f08a03c5ee3b2899b0096afe66014 Mon Sep 17 00:00:00 2001 From: ycc Date: Fri, 16 Dec 2022 22:26:58 +0100 Subject: [PATCH] client to server process outbound generic method --- client/message.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/message.go b/client/message.go index d070d7f..0f7c3a3 100644 --- a/client/message.go +++ b/client/message.go @@ -44,6 +44,25 @@ func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([ return protoPackedServerMsg, nil } +// TODO refactor protobuf to avid 2 methods +func ProcessOutboundMessage(peer *Peer, toServerMessage *meowlib.ToServerMessage, srv *InternalServer) ([]byte, error) { + byteToServerMessage, err := proto.Marshal(toServerMessage) + if err != nil { + return nil, err + } + // Encrypting it + encToServerMessage, encToServerMessageSignature, err := srv.AsymEncryptMessage(byteToServerMessage) + if err != nil { + return nil, err + } + // Packing it + protoPackedServerMsg, err := srv.PackServerMessage(encToServerMessage, encToServerMessageSignature) + if err != nil { + return nil, err + } + return protoPackedServerMsg, nil +} + func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServerMessage, error) { fsmsg := &meowlib.FromServerMessage{} payload, signature, err := srv.UnPackServerMessage(msg)