package client import ( "PD1/internal/protocol" "PD1/internal/utils/cryptoUtils" "PD1/internal/utils/networking" "flag" ) 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.") } //Get user KeyStore password := AskUserPassword() clientKeyStore := cryptoUtils.LoadKeyStore(userFile, password) command := flag.Arg(0) switch command { case "send": if flag.NArg() < 3 { panic("Insufficient arguments for 'send' command. Usage: send ") } uid := flag.Arg(1) //subject := flag.Arg(2) //messageContent := readMessageContent() cl := networking.NewClient[protocol.Packet](&clientKeyStore) defer cl.Connection.Conn.Close() certRequestPacket := protocol.NewRequestUserCertPacket(uid) cl.Connection.Send(certRequestPacket) //certPacket := cl.Connection.Receive() // TODO: Encrypt message //submitMessage(cl, uid, cipherContent) case "askqueue": cl := networking.NewClient[protocol.Packet](&clientKeyStore) defer cl.Connection.Conn.Close() case "getmsg": if flag.NArg() < 2 { panic("Insufficient arguments for 'getmsg' command. Usage: getmsg ") } //num := flag.Arg(1) cl := networking.NewClient[protocol.Packet](&clientKeyStore) defer cl.Connection.Conn.Close() case "help": showHelp() default: commandError() } } func submitMessage(cl networking.Client[protocol.Packet], uid string, content []byte) { pack := protocol.NewSubmitMessagePacket(uid, content) cl.Connection.Send(pack) }