|
86 | 86 | asymmetricMode = flag.Bool("asym", false, "use asymmetric encryption")
|
87 | 87 | generateKey = flag.Bool("generatekey", false, "generate and show the private key")
|
88 | 88 | fileExMode = flag.Bool("fileexchange", false, "file exchange mode")
|
| 89 | + fileReader = flag.Bool("filereader", false, "load and decrypt messages saved as files, display as plain text") |
89 | 90 | testMode = flag.Bool("test", false, "use of predefined parameters for diagnostics (password, etc.)")
|
90 | 91 | echoMode = flag.Bool("echo", false, "echo mode: prints some arguments for diagnostics")
|
91 | 92 |
|
@@ -433,6 +434,8 @@ func run() {
|
433 | 434 | requestExpiredMessagesLoop()
|
434 | 435 | } else if *fileExMode {
|
435 | 436 | sendFilesLoop()
|
| 437 | + } else if *fileReader { |
| 438 | + fileReaderLoop() |
436 | 439 | } else {
|
437 | 440 | sendLoop()
|
438 | 441 | }
|
@@ -483,6 +486,40 @@ func sendFilesLoop() {
|
483 | 486 | }
|
484 | 487 | }
|
485 | 488 |
|
| 489 | +func fileReaderLoop() { |
| 490 | + watcher1 := shh.GetFilter(symFilterID) |
| 491 | + watcher2 := shh.GetFilter(asymFilterID) |
| 492 | + if watcher1 == nil && watcher2 == nil { |
| 493 | + fmt.Println("Error: neither symmetric nor asymmetric filter is installed") |
| 494 | + close(done) |
| 495 | + return |
| 496 | + } |
| 497 | + |
| 498 | + for { |
| 499 | + s := scanLine("") |
| 500 | + if s == quitCommand { |
| 501 | + fmt.Println("Quit command received") |
| 502 | + close(done) |
| 503 | + return |
| 504 | + } |
| 505 | + raw, err := ioutil.ReadFile(s) |
| 506 | + if err != nil { |
| 507 | + fmt.Printf(">>> Error: %s \n", err) |
| 508 | + } else { |
| 509 | + env := whisper.Envelope{Data: raw} // the topic is zero |
| 510 | + msg := env.Open(watcher1) // force-open envelope regardless of the topic |
| 511 | + if msg == nil { |
| 512 | + msg = env.Open(watcher2) |
| 513 | + } |
| 514 | + if msg == nil { |
| 515 | + fmt.Printf(">>> Error: failed to decrypt the message \n") |
| 516 | + } else { |
| 517 | + printMessageInfo(msg) |
| 518 | + } |
| 519 | + } |
| 520 | + } |
| 521 | +} |
| 522 | + |
486 | 523 | func scanLine(prompt string) string {
|
487 | 524 | if len(prompt) > 0 {
|
488 | 525 | fmt.Print(prompt)
|
|
0 commit comments