FromServerMessage processing

This commit is contained in:
ycc 2022-12-09 22:00:31 +01:00
parent d41873f9f3
commit 684d444bc8
2 changed files with 23 additions and 2 deletions

View File

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

View File

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