You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.3 KiB
Go

10 years ago
package main
import (
"flag"
"fmt"
"log"
// "net"
"os"
)
const keyLength = 2048
10 years ago
var (
info_log *log.Logger
error_log *log.Logger
)
var options struct {
10 years ago
port int
host string
key string
publicKey string
nick string
10 years ago
}
func exit(status int, template string, args ...interface{}) {
if status == 0 {
info_log.Printf(template, args...)
} else {
error_log.Printf(template, args...)
}
os.Exit(status)
}
func usage(template string, args ...interface{}) {
fmt.Fprintf(os.Stdout, template, args...)
os.Exit(1)
}
func main() {
flag.Parse()
info_log, error_log = log.New(os.Stdout, "", 0), log.New(os.Stderr, "", 0)
if flag.NArg() < 1 {
usage("client or server?")
}
switch flag.Arg(0) {
case "client":
10 years ago
connect()
case "server":
10 years ago
serve()
case "generate":
generate()
case "encrypt":
encrypt()
case "decrypt":
decrypt()
case "get-public":
getPublic()
default:
usage("i dunno what you mean with %v", flag.Arg(0))
}
}
func init() {
flag.IntVar(&options.port, "port", 9000, "port number")
flag.StringVar(&options.host, "host", "localhost", "host to connect to")
flag.StringVar(&options.key, "key", "whisper_key", "rsa key to use")
10 years ago
flag.StringVar(&options.publicKey, "public-key", "", "public rsa key to use")
10 years ago
flag.StringVar(&options.nick, "nick", "", "nick to use in chat")
}