aerc/lib/crypto/gpg/gpgbin/decrypt.go
Moritz Poldrack 9cffc45f03 go: removed io/ioutil
Since the minimum required version of Go has been bumped to 1.16, the
deprecation of io/ioutil can now be acted upon. This Commit removes the
remaining dependencies on ioutil and replaces them with their io or os
counterparts.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-22 09:30:19 +02:00

36 lines
845 B
Go

package gpgbin
import (
"bytes"
"io"
"git.sr.ht/~rjarry/aerc/models"
)
// Decrypt runs gpg --decrypt on the contents of r. If the packet is signed,
// the signature is also verified
func Decrypt(r io.Reader) (*models.MessageDetails, error) {
md := new(models.MessageDetails)
orig, err := io.ReadAll(r)
if err != nil {
return md, err
}
args := []string{"--decrypt"}
g := newGpg(bytes.NewReader(orig), args)
_ = g.cmd.Run()
outRdr := bytes.NewReader(g.stdout.Bytes())
// Always parse stdout, even if there was an error running command.
// We'll find the error in the parsing
err = parse(outRdr, md)
if err != nil {
err = parseError(g.stderr.String())
switch GPGErrors[err.Error()] {
case ERROR_NO_PGP_DATA_FOUND:
md.Body = bytes.NewReader(orig)
return md, nil
default:
return nil, err
}
}
return md, nil
}