func signFile(keyname, file string) error { privkey, err := ioutil.ReadFile(keyname) if err != nil { return err } fd, err := os.Open(file) if err != nil { return err } defer fd.Close() sig, err := signature.Sign(privkey, fd) if err != nil { return err } out, err := os.Create(file + ".sig") if err != nil { return err } _, err = out.Write(sig) if err != nil { return err } return out.Close() }
func sign(keyname, dataname string) { privkey, err := ioutil.ReadFile(keyname) if err != nil { log.Fatal(err) } var input io.Reader if dataname == "-" || dataname == "" { input = os.Stdin } else { fd, err := os.Open(dataname) if err != nil { log.Fatal(err) } defer fd.Close() input = fd } sig, err := signature.Sign(privkey, input) if err != nil { log.Fatal(err) } os.Stdout.Write(sig) }
func TestSign(t *testing.T) { data := bytes.NewReader([]byte("this is a string to sign")) s, err := signature.Sign(privKey, data) if err != nil { t.Fatal(err) } if !bytes.Contains(s, []byte("SIGNATURE")) { t.Error("should be a signature") } }
func sign(keyname, dataname string) { privkey, err := ioutil.ReadFile(keyname) if err != nil { log.Fatal(err) } fd, err := os.Open(dataname) if err != nil { log.Fatal(err) } defer fd.Close() sig, err := signature.Sign(privkey, fd) if err != nil { log.Fatal(err) } os.Stdout.Write(sig) }