From 1add7e94c9fa3db57f00bc9d3d5ddae319702311 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 22 Sep 2018 06:10:41 -0700 Subject: [PATCH] get receive code if empty --- main.go | 5 ++++- src/sender/sender.go | 6 ++++-- src/utils/getinput.go | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/utils/getinput.go diff --git a/main.go b/main.go index be79c3a..c86811f 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( humanize "github.com/dustin/go-humanize" "github.com/schollz/croc/src/croc" - "github.com/schollz/utils" + "github.com/schollz/croc/src/utils" "github.com/urfave/cli" ) @@ -154,6 +154,9 @@ func receive(c *cli.Context) error { if c.Args().First() != "" { codePhrase = c.Args().First() } + if codePhrase == "" { + codePhrase = utils.GetInput("Enter receive code: ") + } return cr.Receive(codePhrase) } diff --git a/src/sender/sender.go b/src/sender/sender.go index 67d9840..db06970 100644 --- a/src/sender/sender.go +++ b/src/sender/sender.go @@ -110,11 +110,13 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) { log.Debugf("got %d: %s", messageType, message) switch step { case 0: + // send pake data + log.Debugf("[%d] first, P sends u to Q", step) + c.WriteMessage(websocket.BinaryMessage, P.Bytes()) + // start PAKE spinnner spin.Stop() spin.Suffix = " performing PAKE..." spin.Start() - log.Debugf("[%d] first, P sends u to Q", step) - c.WriteMessage(websocket.BinaryMessage, P.Bytes()) case 1: // P recieves H(k),v from Q log.Debugf("[%d] P computes k, H(k), sends H(k) to Q", step) diff --git a/src/utils/getinput.go b/src/utils/getinput.go new file mode 100644 index 0000000..7c397ce --- /dev/null +++ b/src/utils/getinput.go @@ -0,0 +1,15 @@ +package utils + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func GetInput(prompt string) string { + reader := bufio.NewReader(os.Stdin) + fmt.Fprintf(os.Stderr, "%s", prompt) + text, _ := reader.ReadString('\n') + return strings.TrimSpace(text) +}