Exemplo n.º 1
0
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()
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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")
	}
}
Exemplo n.º 4
0
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)
}