aerc/lib/crypto/gpg/gpgbin/sign.go
Moritz Poldrack 70bfcfef42 lint: work nicely with wrapped errors (errorlint)
Error wrapping as introduced in Go 1.13 adds some additional logic to
use for comparing errors and adding information to it.

Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:58:04 +02:00

34 lines
700 B
Go

package gpgbin
import (
"bytes"
"fmt"
"io"
"git.sr.ht/~rjarry/aerc/models"
)
// Sign creates a detached signature based on the contents of r
func Sign(r io.Reader, from string) ([]byte, string, error) {
args := []string{
"--armor",
"--detach-sign",
"--default-key", from,
}
g := newGpg(r, args)
err := g.cmd.Run()
if err != nil {
return nil, "", fmt.Errorf("failed to run signing: %w", err)
}
outRdr := bytes.NewReader(g.stdout.Bytes())
var md models.MessageDetails
err = parse(outRdr, &md)
if err != nil {
return nil, "", fmt.Errorf("failed to parse messagedetails: %w", err)
}
var buf bytes.Buffer
_, _ = io.Copy(&buf, md.Body)
return buf.Bytes(), md.Micalg, nil
}