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)