// TODO: // * Board UI? package main import ( "bytes" "crypto/ed25519" "errors" "flag" "fmt" "io/ioutil" "net/http" "os" "os/user" "path/filepath" "time" "github.com/llimllib/springer/client" ) func fileExists(name string) bool { if _, err := os.Stat(name); errors.Is(err, os.ErrNotExist) { return false } return true } func getKeys(folder string) (ed25519.PublicKey, ed25519.PrivateKey) { // get the expected public key file and private key file paths var pubfile, privfile string if len(folder) == 0 { user, err := user.Current() if err != nil { panic(err) } configPath := os.Getenv("XDG_CONFIG_HOME") if configPath == "" { configPath = filepath.Join(user.HomeDir, ".config", "spring83") } if err = os.MkdirAll(configPath, os.ModePerm); err != nil { panic(err) } pubfile = filepath.Join(configPath, "key.pub") privfile = filepath.Join(configPath, "key.priv") } else { pubfile = filepath.Join(folder, "key.pub") privfile = filepath.Join(folder, "key.priv") } // try to load the public and private key files as ed25519 keys var pubkey ed25519.PublicKey var privkey ed25519.PrivateKey var err error if fileExists(pubfile) && fileExists(privfile) { pubkey, err = ioutil.ReadFile(pubfile) if err != nil { panic(err) } privkey, err = ioutil.ReadFile(privfile) if err != nil { panic(err) } } else { fmt.Println("Generating valid key. This will take a minute") pubkey, privkey = client.ValidKey() os.WriteFile(pubfile, pubkey, 0666) os.WriteFile(privfile, privkey, 0600) } return pubkey, privkey } func getBody(inputFile string) []byte { var body []byte var err error if inputFile == "-" { body, err = ioutil.ReadAll(os.Stdin) if err != nil { panic(err) } } else { body, err = ioutil.ReadFile(inputFile) if err != nil { panic(err) } } // Prepend a time element. Maybe we should check to see if it's already // been provided? timeElt := []byte(fmt.Sprintf("