message helper + io/ioutil deprecation
This commit is contained in:
parent
7ed8ff9982
commit
a5cf1ec7ac
@ -2,7 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ type Config struct {
|
|||||||
GroupChatNotifiactions bool `json:"group_chat_notifiactions,omitempty"`
|
GroupChatNotifiactions bool `json:"group_chat_notifiactions,omitempty"`
|
||||||
ChannelNotifications bool `json:"channel_notifications,omitempty"`
|
ChannelNotifications bool `json:"channel_notifications,omitempty"`
|
||||||
// Inner
|
// Inner
|
||||||
memoryPassword string `json:"memory_password,omitempty"`
|
memoryPassword string
|
||||||
identityFile string `json:"config_file,omitempty"`
|
identityFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance *Config
|
var instance *Config
|
||||||
@ -45,7 +45,7 @@ func GetConfig() *Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Load(filename string) error {
|
func (c *Config) Load(filename string) error {
|
||||||
data, err := ioutil.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func (c *Config) Save(filename string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(filename, data, 0644)
|
os.WriteFile(filename, data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,13 @@ package client
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"forge.redroom.link/yves/meowlib"
|
"forge.redroom.link/yves/meowlib"
|
||||||
"github.com/ProtonMail/gopenpgp/v2/helper"
|
"github.com/ProtonMail/gopenpgp/v2/helper"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const key = "3pw0c8#6ZG8{75b5;3?fe80$2"
|
|
||||||
|
|
||||||
type Identity struct {
|
type Identity struct {
|
||||||
Nickname string `json:"nickname,omitempty"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
|
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
|
||||||
@ -113,7 +111,7 @@ func LoadIdentity(filename string, password string) (*Identity, error) {
|
|||||||
var id Identity
|
var id Identity
|
||||||
GetConfig().memoryPassword = password
|
GetConfig().memoryPassword = password
|
||||||
GetConfig().identityFile = filename
|
GetConfig().identityFile = filename
|
||||||
indata, err := ioutil.ReadFile(filename)
|
indata, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -131,6 +129,6 @@ func (id *Identity) Save() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(GetConfig().identityFile, []byte(armor), 0600)
|
err = os.WriteFile(GetConfig().identityFile, []byte(armor), 0600)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
40
client/message.go
Normal file
40
client/message.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func MakeText(peer *Peer, text string, srv *InternalServer) ([]byte, error) {
|
||||||
|
// Creating User message
|
||||||
|
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
serializedMessage, err := peer.SerializeUserMessage(usermessage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Encrypting it
|
||||||
|
EncMsg, EncMsgSignature, FriendServers, err := peer.AsymEncryptMessage(serializedMessage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(len(FriendServers))
|
||||||
|
// Packing it
|
||||||
|
packedMsg := peer.PackUserMessage(EncMsg, EncMsgSignature)
|
||||||
|
|
||||||
|
// Creating Server message for transporting the user message
|
||||||
|
toServerMessage, err := srv.BuildMessageSendingMessage(&packedMsg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Encrypting it
|
||||||
|
encToServerMessage, encToServerMessageSignature, err := srv.AsymEncryptMessage(toServerMessage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Packing it
|
||||||
|
protoPackedServerMsg, err := srv.PackServerMessage(encToServerMessage, encToServerMessageSignature)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return protoPackedServerMsg, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user