()
| 540 | } |
| 541 | |
| 542 | func run() int { |
| 543 | args := parse_args() |
| 544 | ver := version() |
| 545 | |
| 546 | // handle special invocation modes |
| 547 | if args.showVersion { |
| 548 | fmt.Println(ver) |
| 549 | return 0 |
| 550 | } |
| 551 | |
| 552 | if args.list_ciphers { |
| 553 | list_ciphers() |
| 554 | return 0 |
| 555 | } |
| 556 | |
| 557 | if args.list_curves { |
| 558 | list_curves() |
| 559 | return 0 |
| 560 | } |
| 561 | |
| 562 | if args.passwd != "" { |
| 563 | if err := passwd(args.passwd, args.passwdCost, args.positionalArgs...); err != nil { |
| 564 | log.Fatalf("can't set password: %v", err) |
| 565 | } |
| 566 | return 0 |
| 567 | } |
| 568 | |
| 569 | if args.hmacSign { |
| 570 | if err := hmacSign(args.positionalArgs...); err != nil { |
| 571 | log.Fatalf("can't sign: %v", err) |
| 572 | } |
| 573 | return 0 |
| 574 | } |
| 575 | |
| 576 | if args.hmacGenKey { |
| 577 | if err := hmacGenKey(); err != nil { |
| 578 | log.Fatalf("can't generate key: %v", err) |
| 579 | } |
| 580 | return 0 |
| 581 | } |
| 582 | |
| 583 | switch args.mode.value { |
| 584 | case proxyModeStdIO, proxyModePortForward: |
| 585 | // expect exactly two positional arguments |
| 586 | if len(args.positionalArgs) != 2 { |
| 587 | arg_fail("Exactly two positional arguments are expected in this mode: host and port") |
| 588 | } |
| 589 | default: |
| 590 | // we don't expect positional arguments in the main operation mode |
| 591 | if len(args.positionalArgs) > 0 { |
| 592 | arg_fail("Unexpected positional arguments! Check your command line.") |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | // setup logging |
| 597 | logWriter := clog.NewLogWriter(os.Stderr, 128) |
| 598 | defer func() { |
| 599 | ctx, cl := context.WithTimeout(context.Background(), 1*time.Second) |
no test coverage detected