ProcessUserMessage

This commit is contained in:
ycc 2022-12-17 19:57:02 +01:00
parent b50098d04e
commit 39dab226fb
2 changed files with 21 additions and 0 deletions

View File

@ -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
}

View File

@ -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)