aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/gpg/gpgbin
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-29 22:31:54 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:57:57 +0200
commit5ca6022d007bc83daba1e7297480d37f56554455 (patch)
treecc592d08276b7f0c8db6a4280bb7fb648b2548fe /lib/crypto/gpg/gpgbin
parenta8d631177f4315810f0ab7c7d66d38e332ab0916 (diff)
downloadaerc-5ca6022d007bc83daba1e7297480d37f56554455.tar.gz
lint: ensure errors are at least logged (errcheck)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/crypto/gpg/gpgbin')
-rw-r--r--lib/crypto/gpg/gpgbin/encrypt.go9
-rw-r--r--lib/crypto/gpg/gpgbin/gpgbin.go12
-rw-r--r--lib/crypto/gpg/gpgbin/keys.go5
-rw-r--r--lib/crypto/gpg/gpgbin/sign.go9
-rw-r--r--lib/crypto/gpg/gpgbin/verify.go13
5 files changed, 36 insertions, 12 deletions
diff --git a/lib/crypto/gpg/gpgbin/encrypt.go b/lib/crypto/gpg/gpgbin/encrypt.go
index 31245a74..9ca45269 100644
--- a/lib/crypto/gpg/gpgbin/encrypt.go
+++ b/lib/crypto/gpg/gpgbin/encrypt.go
@@ -25,15 +25,18 @@ func Encrypt(r io.Reader, to []string, from string) ([]byte, error) {
args = append(args, "--encrypt", "-")
g := newGpg(r, args)
- g.cmd.Run()
+ err := g.cmd.Run()
+ if err != nil {
+ return nil, fmt.Errorf("gpg: failed to run encryption: %w", err)
+ }
outRdr := bytes.NewReader(g.stdout.Bytes())
var md models.MessageDetails
- err := parse(outRdr, &md)
+ err = parse(outRdr, &md)
if err != nil {
return nil, fmt.Errorf("gpg: failure to encrypt: %v. check public key(s)", err)
}
var buf bytes.Buffer
- io.Copy(&buf, md.Body)
+ _, _ = io.Copy(&buf, md.Body)
return buf.Bytes(), nil
}
diff --git a/lib/crypto/gpg/gpgbin/gpgbin.go b/lib/crypto/gpg/gpgbin/gpgbin.go
index 2eb83dc9..1e8c7dcd 100644
--- a/lib/crypto/gpg/gpgbin/gpgbin.go
+++ b/lib/crypto/gpg/gpgbin/gpgbin.go
@@ -63,7 +63,11 @@ func getIdentity(key uint64) string {
var outbuf strings.Builder
cmd.Stdout = &outbuf
- cmd.Run()
+ err := cmd.Run()
+ if err != nil {
+ logging.Errorf("gpg: failed to get identity: %v", err)
+ return ""
+ }
out := strings.Split(outbuf.String(), "\n")
for _, line := range out {
if strings.HasPrefix(line, "uid") {
@@ -85,7 +89,11 @@ func getKeyId(s string, private bool) string {
var outbuf strings.Builder
cmd.Stdout = &outbuf
- cmd.Run()
+ err := cmd.Run()
+ if err != nil {
+ logging.Errorf("gpg: failed to get key ID: %v", err)
+ return ""
+ }
out := strings.Split(outbuf.String(), "\n")
for _, line := range out {
if strings.HasPrefix(line, "fpr") {
diff --git a/lib/crypto/gpg/gpgbin/keys.go b/lib/crypto/gpg/gpgbin/keys.go
index bef90cf6..ca166e9d 100644
--- a/lib/crypto/gpg/gpgbin/keys.go
+++ b/lib/crypto/gpg/gpgbin/keys.go
@@ -36,7 +36,10 @@ func ExportPublicKey(k string) (io.Reader, error) {
var stderr strings.Builder
cmd.Stdout = &outbuf
cmd.Stderr = &stderr
- cmd.Run()
+ err := cmd.Run()
+ if err != nil {
+ return nil, fmt.Errorf("gpg: export failed: %w", err)
+ }
if strings.Contains(stderr.String(), "gpg") {
return nil, fmt.Errorf("gpg: error exporting key")
}
diff --git a/lib/crypto/gpg/gpgbin/sign.go b/lib/crypto/gpg/gpgbin/sign.go
index 31fd2b5a..caf31d14 100644
--- a/lib/crypto/gpg/gpgbin/sign.go
+++ b/lib/crypto/gpg/gpgbin/sign.go
@@ -17,15 +17,18 @@ func Sign(r io.Reader, from string) ([]byte, string, error) {
}
g := newGpg(r, args)
- g.cmd.Run()
+ 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)
+ 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)
+ _, _ = io.Copy(&buf, md.Body)
return buf.Bytes(), md.Micalg, nil
}
diff --git a/lib/crypto/gpg/gpgbin/verify.go b/lib/crypto/gpg/gpgbin/verify.go
index be9f26f7..e5930849 100644
--- a/lib/crypto/gpg/gpgbin/verify.go
+++ b/lib/crypto/gpg/gpgbin/verify.go
@@ -2,6 +2,7 @@ package gpgbin
import (
"bytes"
+ "fmt"
"io"
"io/ioutil"
"os"
@@ -19,7 +20,7 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
if err != nil {
return nil, err
}
- io.Copy(sig, s)
+ _, _ = io.Copy(sig, s)
sig.Close()
defer os.Remove(sig.Name())
args = append(args, sig.Name(), "-")
@@ -29,11 +30,17 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
return nil, err
}
g := newGpg(bytes.NewReader(orig), args)
- g.cmd.Run()
+ err = g.cmd.Run()
+ if err != nil {
+ return nil, fmt.Errorf("gpg: failed to run verification: %w", err)
+ }
out := bytes.NewReader(g.stdout.Bytes())
md := new(models.MessageDetails)
- parse(out, md)
+ err = parse(out, md)
+ if err != nil {
+ return nil, fmt.Errorf("gpg: failed to parse result: %w", err)
+ }
md.Body = bytes.NewReader(orig)