diff --git a/client/message.go b/client/message.go index 7030107..488d888 100644 --- a/client/message.go +++ b/client/message.go @@ -1,6 +1,11 @@ package client -import "fmt" +import ( + "fmt" + + "forge.redroom.link/yves/meowlib" + "google.golang.org/protobuf/proto" +) func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([]byte, error) { // Creating User message @@ -38,3 +43,19 @@ func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([ } return protoPackedServerMsg, nil } + +func ProcessServerResponse(srv *InternalServer, msg []byte) (fsmsg *meowlib.FromServerMessage, err error) { + + payload, signature, err := srv.UnPackServerMessage(msg) + if err != nil { + return nil, err + } + decrypted, err := srv.AsymDecryptMessage(payload, signature) + if err != nil { + return nil, err + } + if err := proto.Unmarshal(decrypted, fsmsg); err != nil { + return nil, err + } + return fsmsg, nil +} diff --git a/client/peer.go b/client/peer.go index 6bbd644..3a5e660 100644 --- a/client/peer.go +++ b/client/peer.go @@ -151,7 +151,7 @@ func (p *Peer) PackUserMessage(message []byte, signature []byte) *meowlib.Packed return &msg } -func (ints *InternalServer) UnPackUserMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) { +func (p *Peer) UnPackUserMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) { msg := &meowlib.PackedServerMessage{} if err := proto.Unmarshal(protoPackedMessage, msg); err != nil { return nil, nil, err