80f90c0d41
Fix the following error: panic() runtime/panic.go:838 bytes.(*Buffer).ReadFrom() bytes/buffer.go:204 io.copyBuffer() io/io.go:412 io.Copy() io/io.go:385 git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin.Sign() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin/sign.go:25 git.sr.ht/~rjarry/aerc/lib/crypto/gpg.(*Signer).Close() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/writer.go:52 git.sr.ht/~rjarry/aerc/lib/crypto/gpg.multiCloser.Close() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/writer.go:92 git.sr.ht/~rjarry/aerc/widgets.(*Composer).WriteMessage() git.sr.ht/~rjarry/aerc/widgets/compose.go:601 git.sr.ht/~rjarry/aerc/commands/compose.Send.Execute.func1() git.sr.ht/~rjarry/aerc/commands/compose/send.go:127 Fixes: https://todo.sr.ht/~rjarry/aerc/53 Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
31 lines
604 B
Go
31 lines
604 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)
|
|
g.cmd.Run()
|
|
|
|
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: %v", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
io.Copy(&buf, md.Body)
|
|
return buf.Bytes(), md.Micalg, nil
|
|
}
|