aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/gpg
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-31 15:15:27 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:58:04 +0200
commit70bfcfef42578079f211d87cddc49519ee3503dc (patch)
treeae35c38e3980c73af2b43be10fe8cc9ece4f3f9a /lib/crypto/gpg
parent978d35d356e8752bdd272884df48a6289d88b40a (diff)
downloadaerc-70bfcfef42578079f211d87cddc49519ee3503dc.tar.gz
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>
Diffstat (limited to 'lib/crypto/gpg')
-rw-r--r--lib/crypto/gpg/gpgbin/encrypt.go2
-rw-r--r--lib/crypto/gpg/gpgbin/sign.go2
-rw-r--r--lib/crypto/gpg/reader.go22
3 files changed, 13 insertions, 13 deletions
diff --git a/lib/crypto/gpg/gpgbin/encrypt.go b/lib/crypto/gpg/gpgbin/encrypt.go
index 9ca45269..79003fd5 100644
--- a/lib/crypto/gpg/gpgbin/encrypt.go
+++ b/lib/crypto/gpg/gpgbin/encrypt.go
@@ -33,7 +33,7 @@ func Encrypt(r io.Reader, to []string, from string) ([]byte, error) {
var md models.MessageDetails
err = parse(outRdr, &md)
if err != nil {
- return nil, fmt.Errorf("gpg: failure to encrypt: %v. check public key(s)", err)
+ return nil, fmt.Errorf("gpg: failure to encrypt: %w. check public key(s)", err)
}
var buf bytes.Buffer
_, _ = io.Copy(&buf, md.Body)
diff --git a/lib/crypto/gpg/gpgbin/sign.go b/lib/crypto/gpg/gpgbin/sign.go
index caf31d14..314c3fc3 100644
--- a/lib/crypto/gpg/gpgbin/sign.go
+++ b/lib/crypto/gpg/gpgbin/sign.go
@@ -26,7 +26,7 @@ func Sign(r io.Reader, from string) ([]byte, string, error) {
var md models.MessageDetails
err = parse(outRdr, &md)
if err != nil {
- return nil, "", fmt.Errorf("failed to parse messagedetails: %v", err)
+ return nil, "", fmt.Errorf("failed to parse messagedetails: %w", err)
}
var buf bytes.Buffer
_, _ = io.Copy(&buf, md.Body)
diff --git a/lib/crypto/gpg/reader.go b/lib/crypto/gpg/reader.go
index 40da82f8..07553c97 100644
--- a/lib/crypto/gpg/reader.go
+++ b/lib/crypto/gpg/reader.go
@@ -61,12 +61,12 @@ func Read(r io.Reader) (*Reader, error) {
func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Reader, error) {
p, err := mr.NextPart()
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read first part in multipart/encrypted message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read first part in multipart/encrypted message: %w", err)
}
t, _, err := mime.ParseMediaType(p.Header.Get("Content-Type"))
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to parse Content-Type of first part in multipart/encrypted message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to parse Content-Type of first part in multipart/encrypted message: %w", err)
}
if !strings.EqualFold(t, "application/pgp-encrypted") {
return nil, fmt.Errorf("gpgmail: first part in multipart/encrypted message has type %q, not application/pgp-encrypted", t)
@@ -74,7 +74,7 @@ func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Rea
metadata, err := textproto.ReadHeader(bufio.NewReader(p))
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to parse application/pgp-encrypted part: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to parse application/pgp-encrypted part: %w", err)
}
if s := metadata.Get("Version"); s != "1" {
return nil, fmt.Errorf("gpgmail: unsupported PGP/MIME version: %q", s)
@@ -82,11 +82,11 @@ func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Rea
p, err = mr.NextPart()
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read second part in multipart/encrypted message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read second part in multipart/encrypted message: %w", err)
}
t, _, err = mime.ParseMediaType(p.Header.Get("Content-Type"))
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to parse Content-Type of second part in multipart/encrypted message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to parse Content-Type of second part in multipart/encrypted message: %w", err)
}
if !strings.EqualFold(t, "application/octet-stream") {
return nil, fmt.Errorf("gpgmail: second part in multipart/encrypted message has type %q, not application/octet-stream", t)
@@ -94,13 +94,13 @@ func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Rea
md, err := gpgbin.Decrypt(p)
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read PGP message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read PGP message: %w", err)
}
cleartext := bufio.NewReader(md.Body)
cleartextHeader, err := textproto.ReadHeader(cleartext)
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read encrypted header: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read encrypted header: %w", err)
}
t, params, err := mime.ParseMediaType(cleartextHeader.Get("Content-Type"))
@@ -114,7 +114,7 @@ func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Rea
mr := textproto.NewMultipartReader(cleartext, params["boundary"])
mds, err := newSignedReader(cleartextHeader, mr, micalg)
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read encapsulated multipart/signed message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read encapsulated multipart/signed message: %w", err)
}
mds.MessageDetails.IsEncrypted = md.IsEncrypted
mds.MessageDetails.DecryptedWith = md.DecryptedWith
@@ -136,7 +136,7 @@ func newSignedReader(h textproto.Header, mr *textproto.MultipartReader, micalg s
micalg = strings.ToLower(micalg)
p, err := mr.NextPart()
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read signed part in multipart/signed message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read signed part in multipart/signed message: %w", err)
}
var headerBuf bytes.Buffer
_ = textproto.WriteHeader(&headerBuf, p.Header)
@@ -147,12 +147,12 @@ func newSignedReader(h textproto.Header, mr *textproto.MultipartReader, micalg s
sig, err := mr.NextPart()
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read pgp part in multipart/signed message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read pgp part in multipart/signed message: %w", err)
}
md, err := gpgbin.Verify(&msg, sig)
if err != nil {
- return nil, fmt.Errorf("gpgmail: failed to read PGP message: %v", err)
+ return nil, fmt.Errorf("gpgmail: failed to read PGP message: %w", err)
}
if md.Micalg != micalg && md.SignatureError == "" {
md.SignatureError = "gpg: header hash does not match actual sig hash"