afonso
cdaae8fb7e
Still need to create crypto object and use it to encrypt messages Need to create TLS still
60 lines
1.5 KiB
Go
60 lines
1.5 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: cipherSubject := CHAMAR CRYPTO
|
|
// TODO: cipherBody := CHAMAR CRYPTO
|
|
submitMessage(cl,uid,cipherSubject,cipherBody)
|
|
|
|
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,subject []byte,body []byte) {
|
|
pack := protocol.NewSubmitMessage(uid, subject, body)
|
|
cl.Connection.Send(pack)
|
|
}
|