Sign takes an *openpgp.Entity

This commit is contained in:
Stephen McQuay 2018-02-27 20:41:57 -08:00
parent e043384c67
commit 0cee922f12
Signed by untrusted user: sm
GPG Key ID: 4E4B72F479BA3CE5
2 changed files with 7 additions and 15 deletions

View File

@ -90,7 +90,11 @@ func main() {
if signID == "" {
fatalf("must set PM_PGP_ID\n")
}
if err := keyring.Sign(root, signID, os.Stdin, os.Stdout); err != nil {
e, err := keyring.FindSecretEntity(root, signID)
if err != nil {
fatalf("find secret key: %v\n", err)
}
if err := keyring.Sign(e, os.Stdin, os.Stdout); err != nil {
fatalf("signing: %v\n", err)
}
case "verify", "v":

View File

@ -184,20 +184,8 @@ func Import(root string, w io.Reader) error {
}
// Sign takes an id and a reader and writes the signature for that id to sig.
func Sign(root, id string, in io.Reader, sig io.Writer) error {
if err := ensureDir(root); err != nil {
return errors.Wrap(err, "can't find or create pgp dir")
}
srn, prn := getNames(root)
secs, _, err := getELs(srn, prn)
if err != nil {
return errors.Wrap(err, "getting existing keyrings")
}
e, err := findKey(secs, id)
if err != nil {
return errors.Wrapf(err, "finding key %q", id)
}
if err := openpgp.ArmoredDetachSign(sig, e, in, nil); err != nil {
func Sign(key *openpgp.Entity, in io.Reader, sig io.Writer) error {
if err := openpgp.ArmoredDetachSign(sig, key, in, nil); err != nil {
return errors.Wrap(err, "armored detach sign")
}
fmt.Fprintf(sig, "\n")