From e3b2b43dac500bc6a40fae5331a9334ce26369a2 Mon Sep 17 00:00:00 2001 From: Lukas Burkhalter Date: Thu, 23 Nov 2023 11:42:02 +0100 Subject: [PATCH] refactor(test): Handle errors if possible --- openpgp/clearsign/clearsign.go | 4 +++- openpgp/keys_test.go | 4 +++- openpgp/packet/symmetric_key_encrypted_test.go | 3 +++ openpgp/v2/keys.go | 1 - openpgp/v2/keys_test.go | 4 +++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/openpgp/clearsign/clearsign.go b/openpgp/clearsign/clearsign.go index 5103859c..33fa8e5a 100644 --- a/openpgp/clearsign/clearsign.go +++ b/openpgp/clearsign/clearsign.go @@ -289,7 +289,9 @@ func (d *dashEscaper) Write(data []byte) (n int, err error) { } d.whitespace = d.whitespace[:0] } - d.toHash.Write(d.byteBuf) + if _, err = d.toHash.Write(d.byteBuf); err != nil { + return + } if err = d.buffered.WriteByte(b); err != nil { return } diff --git a/openpgp/keys_test.go b/openpgp/keys_test.go index 1b99c6fb..bd0bf322 100644 --- a/openpgp/keys_test.go +++ b/openpgp/keys_test.go @@ -1388,7 +1388,9 @@ func TestRevokeSubkey(t *testing.T) { } serializedEntity := bytes.NewBuffer(nil) - entity.SerializePrivate(serializedEntity, nil) + if err := entity.SerializePrivate(serializedEntity, nil); err != nil { + t.Fatal(err) + } // Make sure revocation reason subpackets are not lost during serialization. newEntity, err := ReadEntity(packet.NewReader(bytes.NewBuffer(serializedEntity.Bytes()))) diff --git a/openpgp/packet/symmetric_key_encrypted_test.go b/openpgp/packet/symmetric_key_encrypted_test.go index b4cec75f..6896d68d 100644 --- a/openpgp/packet/symmetric_key_encrypted_test.go +++ b/openpgp/packet/symmetric_key_encrypted_test.go @@ -102,6 +102,9 @@ func TestSerializeSymmetricKeyEncryptedV6RandomizeSlow(t *testing.T) { } key, err := SerializeSymmetricKeyEncrypted(&buf, passphrase, config) + if err != nil { + t.Errorf("failed to serialize %s", err) + } p, err := Read(&buf) if err != nil { t.Errorf("failed to reparse %s", err) diff --git a/openpgp/v2/keys.go b/openpgp/v2/keys.go index 4aa403c9..61bdb027 100644 --- a/openpgp/v2/keys.go +++ b/openpgp/v2/keys.go @@ -427,7 +427,6 @@ func readToNextPublicKey(packets *packet.Reader) (err error) { return } else if err != nil { if _, ok := err.(errors.UnsupportedError); ok { - err = nil continue } return diff --git a/openpgp/v2/keys_test.go b/openpgp/v2/keys_test.go index 567a941b..6f037f5f 100644 --- a/openpgp/v2/keys_test.go +++ b/openpgp/v2/keys_test.go @@ -1446,7 +1446,9 @@ func TestRevokeSubkey(t *testing.T) { } serializedEntity := bytes.NewBuffer(nil) - entity.SerializePrivate(serializedEntity, nil) + if err := entity.SerializePrivate(serializedEntity, nil); err != nil { + t.Fatal(err) + } // Make sure revocation reason subpackets are not lost during serialization. newEntity, err := ReadEntity(packet.NewReader(bytes.NewBuffer(serializedEntity.Bytes())))