63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package client
|
|
|
|
import (
|
|
"PD1/internal/protocol"
|
|
"PD1/internal/utils/networking"
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
func Run() {
|
|
var userFile string
|
|
flag.StringVar(&userFile, "user", "userdata.p12", "Specify user data file")
|
|
flag.Parse()
|
|
|
|
if flag.NArg() == 0 {
|
|
panic("No command provided. Use 'help' for instructions.")
|
|
}
|
|
|
|
command := flag.Arg(0)
|
|
switch command {
|
|
case "send":
|
|
if flag.NArg() < 3 {
|
|
panic("Insufficient arguments for 'send' command. Usage: send <UID> <SUBJECT>")
|
|
}
|
|
uid := flag.Arg(1)
|
|
subject := flag.Arg(2)
|
|
// Read message content from stdin
|
|
messageContent := readMessageContent()
|
|
cl := networking.NewClient[protocol.Packet]()
|
|
defer cl.Connection.Conn.Close()
|
|
// TODO: getuserinfo client cert
|
|
// TODO: ask server for the recieving client's cert
|
|
certRequestPacket := protocol.NewRequestPubKey()
|
|
cl.Connection.Send(certRequestPacket)
|
|
certPacket := cl.Connection.Receive()
|
|
// TODO: cipherContent := cryptoUtils.encryptMessageContent()
|
|
submitMessage(cl,uid,cipherContent)
|
|
|
|
case "askqueue":
|
|
cl := networking.NewClient[protocol.Packet]()
|
|
defer cl.Connection.Conn.Close()
|
|
|
|
case "getmsg":
|
|
if flag.NArg() < 2 {
|
|
panic("Insufficient arguments for 'getmsg' command. Usage: getmsg <NUM>")
|
|
}
|
|
num := flag.Arg(1)
|
|
cl := networking.NewClient[protocol.Packet]()
|
|
defer cl.Connection.Conn.Close()
|
|
|
|
case "help":
|
|
showHelp()
|
|
|
|
default:
|
|
fmt.Println("Invalid command. Use 'help' for instructions.")
|
|
}
|
|
|
|
}
|
|
|
|
func submitMessage(cl networking.Client[protocol.Packet],uid string, content []byte) {
|
|
pack := protocol.NewSubmitMessage(uid,content)
|
|
cl.Connection.Send(pack)
|
|
}
|