diff --git a/client/message.go b/client/message.go index 1ceebb6..7071b80 100644 --- a/client/message.go +++ b/client/message.go @@ -78,3 +78,15 @@ func ProcessServerResponse(srv *InternalServer, msg []byte) (*meowlib.FromServer } return fsmsg, nil } + +func ProcessUserMessage(peer Peer, message []byte, signature []byte) (*meowlib.UserMessage, error) { + dec, err := peer.AsymDecryptMessage(message, signature) + if err != nil { + return nil, err + } + msg, err := peer.DeserializeUserMessage(dec) + if err != nil { + return nil, err + } + return msg, nil +} diff --git a/client/peer.go b/client/peer.go index c435a92..c3e83a9 100644 --- a/client/peer.go +++ b/client/peer.go @@ -142,6 +142,15 @@ func (p *Peer) SerializeUserMessage(msg *meowlib.UserMessage) ([]byte, error) { return out, nil } +func (p *Peer) DeserializeUserMessage(data []byte) (*meowlib.UserMessage, error) { + var msg meowlib.UserMessage + err := proto.Unmarshal(data, &msg) + if err != nil { + return nil, err + } + return &msg, nil +} + // AsymEncryptMessage prepares a message to send to a specific peer contact func (p *Peer) AsymEncryptMessage(Message []byte) (EncryptedMessage []byte, Signature []byte, Servers []*meowlib.Server, err error) { EncryptedMessage, Signature, err = meowlib.AsymEncryptAndSign(p.Contact.EncryptionPublicKey, p.MyIdentity.Private, Message)