Add keyring support #1

Manually merged
sm merged 1 commits from keyring into master 2018-02-27 20:41:57 -08:00
2 changed files with 7 additions and 15 deletions

View File

@ -90,7 +90,11 @@ func main() {
if signID == "" { if signID == "" {
fatalf("must set PM_PGP_ID\n") 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) fatalf("signing: %v\n", err)
} }
case "verify", "v": 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. // 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 { func Sign(key *openpgp.Entity, in io.Reader, sig io.Writer) error {
if err := ensureDir(root); err != nil { if err := openpgp.ArmoredDetachSign(sig, key, in, nil); 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 {
return errors.Wrap(err, "armored detach sign") return errors.Wrap(err, "armored detach sign")
} }
fmt.Fprintf(sig, "\n") fmt.Fprintf(sig, "\n")