6b1afc3ae3
Fix the following test failures: FAIL: TestMessageInfoHandledError (0.00s) parse_test.go:53: could not parse envelope: date parsing failed: unrecognized date format: FAIL: TestReader (0.07s) gpg_test.go:27: using GNUPGHOME = /tmp/TestReader2384941142/001 reader_test.go:108: Test case: Invalid Signature reader_test.go:112: gpg.Read() = gpgmail: failed to read PGP message: gpg: failed to run verification: exit status 1 Fixes:5ca6022d00
("lint: ensure errors are at least logged (errcheck)") Fixes:70bfcfef42
("lint: work nicely with wrapped errors (errorlint)") Signed-off-by: Robin Jarry <robin@jarry.cc> Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
41 lines
862 B
Go
41 lines
862 B
Go
package gpgbin
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
|
)
|
|
|
|
// Verify runs gpg --verify. If s is not nil, then gpg interprets the
|
|
// arguments as a detached signature
|
|
func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
|
|
args := []string{"--verify"}
|
|
if s != nil {
|
|
// Detached sig, save the sig to a tmp file and send msg over stdin
|
|
sig, err := ioutil.TempFile("", "sig")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, _ = io.Copy(sig, s)
|
|
sig.Close()
|
|
defer os.Remove(sig.Name())
|
|
args = append(args, sig.Name(), "-")
|
|
}
|
|
orig, err := ioutil.ReadAll(m)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
g := newGpg(bytes.NewReader(orig), args)
|
|
_ = g.cmd.Run()
|
|
|
|
out := bytes.NewReader(g.stdout.Bytes())
|
|
md := new(models.MessageDetails)
|
|
_ = parse(out, md)
|
|
|
|
md.Body = bytes.NewReader(orig)
|
|
|
|
return md, nil
|
|
}
|