locks + message helper rename

This commit is contained in:
ycc 2022-12-03 00:05:28 +01:00
parent a5cf1ec7ac
commit 023a3c701a
7 changed files with 19 additions and 19 deletions

View File

@ -3,8 +3,8 @@ package meowlib
import ( import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -123,19 +123,19 @@ func TestFlutterCompat(t *testing.T) {
} }
func TestFlutterDecode(t *testing.T) { func TestFlutterDecode(t *testing.T) {
pub, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/pub.key") pub, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/pub.key")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
priv, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/priv.key") priv, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/priv.key")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
msg, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/msg.enc") msg, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/msg.enc")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
sign, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/msg.sign") sign, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/msg.sign")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
@ -154,11 +154,11 @@ func TestFlutterDecode(t *testing.T) {
} }
func TestFlutterEncode(t *testing.T) { func TestFlutterEncode(t *testing.T) {
pub, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/pub.key") pub, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/pub.key")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
priv, err := ioutil.ReadFile("/home/yves/Documents/code/flutter/meowlib/priv.key") priv, err := os.ReadFile("/home/yves/Documents/code/flutter/meowlib/priv.key")
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
@ -168,11 +168,11 @@ func TestFlutterEncode(t *testing.T) {
log.Println(err.Error()) log.Println(err.Error())
} }
err = ioutil.WriteFile("/home/yves/Documents/code/flutter/meowlib/gomsg.enc", encMess, 0644) err = os.WriteFile("/home/yves/Documents/code/flutter/meowlib/gomsg.enc", encMess, 0644)
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }
err = ioutil.WriteFile("/home/yves/Documents/code/flutter/meowlib/gomsg.sign", sign2, 0644) err = os.WriteFile("/home/yves/Documents/code/flutter/meowlib/gomsg.sign", sign2, 0644)
if err != nil { if err != nil {
fmt.Println("Err") fmt.Println("Err")
} }

View File

@ -48,8 +48,8 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerI
} }
} }
for _, i := range MessageServerIdxs { for _, i := range MessageServerIdxs {
srv := id.MessageServers.Servers[i].ServerData srv := &id.MessageServers.Servers[i].ServerData
myContactCard.PullServers = append(myContactCard.PullServers, &srv) myContactCard.PullServers = append(myContactCard.PullServers, srv)
} }
myContactCard.Name = MyName myContactCard.Name = MyName
myContactCard.ContactPublicKey = peer.MyIdentity.Public myContactCard.ContactPublicKey = peer.MyIdentity.Public

View File

@ -2,7 +2,7 @@ package client
import "fmt" import "fmt"
func MakeText(peer *Peer, text string, srv *InternalServer) ([]byte, error) { func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([]byte, error) {
// Creating User message // Creating User message
usermessage, err := peer.BuildSimpleUserMessage([]byte(text)) usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
if err != nil { if err != nil {
@ -22,7 +22,7 @@ func MakeText(peer *Peer, text string, srv *InternalServer) ([]byte, error) {
packedMsg := peer.PackUserMessage(EncMsg, EncMsgSignature) packedMsg := peer.PackUserMessage(EncMsg, EncMsgSignature)
// Creating Server message for transporting the user message // Creating Server message for transporting the user message
toServerMessage, err := srv.BuildMessageSendingMessage(&packedMsg) toServerMessage, err := srv.BuildMessageSendingMessage(packedMsg)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -143,12 +143,12 @@ func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMe
} }
// PackUserMessage will package the previously encrypted message for sending it to the peer in protobuff format // PackUserMessage will package the previously encrypted message for sending it to the peer in protobuff format
func (p *Peer) PackUserMessage(message []byte, signature []byte) meowlib.PackedUserMessage { func (p *Peer) PackUserMessage(message []byte, signature []byte) *meowlib.PackedUserMessage {
var msg meowlib.PackedUserMessage var msg meowlib.PackedUserMessage
msg.Destination = p.Contact.LookupPublicKey msg.Destination = p.Contact.LookupPublicKey
msg.Payload = message msg.Payload = message
msg.Signature = signature msg.Signature = signature
return msg return &msg
} }
func (ints *InternalServer) UnPackUserMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) { func (ints *InternalServer) UnPackUserMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) {

View File

@ -159,10 +159,10 @@ func (Contact *ContactCard) WriteQr(filename string) error {
return nil return nil
} }
func ReadQr(Filename string) ContactCard { func ReadQr(filename string) *ContactCard {
var contact ContactCard var contact ContactCard
// open and decode image file // open and decode image file
file, _ := os.Open("qrcode.jpg") file, _ := os.Open(filename)
img, _, _ := image.Decode(file) img, _, _ := image.Decode(file)
// prepare BinaryBitmap // prepare BinaryBitmap
@ -173,5 +173,5 @@ func ReadQr(Filename string) ContactCard {
result, _ := qrReader.Decode(bmp, nil) result, _ := qrReader.Decode(bmp, nil)
fmt.Println(result) fmt.Println(result)
return contact return &contact
} }

View File

@ -103,7 +103,7 @@ func TestEndToEnd(t *testing.T) {
intS1 := client.InternalServerFromServer(srv) intS1 := client.InternalServerFromServer(srv)
// Creating Server message for transporting the user message // Creating Server message for transporting the user message
toServerMessage, err := intS1.BuildMessageSendingMessage(&packedMsg) toServerMessage, err := intS1.BuildMessageSendingMessage(packedMsg)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB