meowlib/server.go

54 lines
1.5 KiB
Go
Raw Normal View History

2022-01-15 22:19:29 +01:00
package meowlib
2021-10-18 21:05:44 +02:00
2022-09-05 17:16:11 +02:00
import (
"fmt"
"time"
)
2022-01-15 22:19:29 +01:00
type InternalServer struct {
ServerData Server `json:"server_data,omitempty"`
Presence bool `json:"presence,omitempty"`
LastCheck time.Time `json:"last_check,omitempty"`
Uptime time.Duration `json:"uptime,omitempty"`
Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"`
Me KeyPair `json:"me,omitempty"`
}
type ServerList struct {
Name string
Servers []InternalServer
}
func ServerFromUrl(url string) *InternalServer {
var is InternalServer
is.ServerData.Url = url
return &is
}
func (sl *ServerList) AddUrls(urls []string) {
for _, url := range urls {
sl.Servers = append(sl.Servers, *ServerFromUrl(url))
}
2021-10-18 21:05:44 +02:00
}
2022-09-05 17:16:11 +02:00
func (ints *InternalServer) AsymEncryptMessage(Message []byte) (EncryptedMsg []byte, Signature []byte, err error) {
// prepares a message to send to a specific internal server
EncryptedMsg, Signature, err = EncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message)
if err != nil {
fmt.Println(err.Error())
return nil, nil, err
}
return EncryptedMsg, Signature, err
}
func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMsg []byte, err error) {
// reads a message from a specific internal server
DecryptedMsg, err = DecryptAndCheck(ints.Me.Private, ints.ServerData.PublicKey, Message, Signature)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
return DecryptedMsg, err
}