Skip to content

Commit c99f7e5

Browse files
committed
fix: Address warnings
1 parent d5a01d4 commit c99f7e5

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

Diff for: openpgp/forwarding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func (e *Entity) NewForwardingEntity(
134134
instance.ForwardeeFingerprint = forwardeeSubKey.PublicKey.Fingerprint
135135

136136
// 0x04 - This key may be used to encrypt communications.
137-
forwardeeSubKey.Sig.FlagEncryptCommunications = false
137+
forwardeeSubKey.Sig.FlagEncryptCommunications = true
138138

139139
// 0x08 - This key may be used to encrypt storage.
140-
forwardeeSubKey.Sig.FlagEncryptStorage = false
140+
forwardeeSubKey.Sig.FlagEncryptStorage = true
141141

142142
// 0x10 - The private component of this key may have been split by a secret-sharing mechanism.
143143
forwardeeSubKey.Sig.FlagSplitKey = true

Diff for: openpgp/forwarding_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"bytes"
55
"crypto/rand"
66
goerrors "errors"
7-
"github.com/ProtonMail/go-crypto/openpgp/packet"
8-
"golang.org/x/crypto/openpgp/armor"
97
"io"
108
"io/ioutil"
119
"strings"
1210
"testing"
11+
12+
"github.com/ProtonMail/go-crypto/openpgp/packet"
13+
"golang.org/x/crypto/openpgp/armor"
1314
)
1415

1516
const forwardeeKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
@@ -59,7 +60,7 @@ func TestForwardingStatic(t *testing.T) {
5960

6061
dec, err := ioutil.ReadAll(m.decrypted)
6162

62-
if bytes.Compare(dec, []byte(forwardedPlaintext)) != 0 {
63+
if !bytes.Equal(dec, []byte(forwardedPlaintext)) {
6364
t.Fatal("forwarded decrypted does not match original")
6465
}
6566
}
@@ -89,11 +90,11 @@ func TestForwardingFull(t *testing.T) {
8990
t.Fatalf("invalid number of instances, expected 1 got %d", len(instances))
9091
}
9192

92-
if bytes.Compare(instances[0].ForwarderFingerprint, bobEntity.Subkeys[0].PublicKey.Fingerprint) != 0 {
93+
if !bytes.Equal(instances[0].ForwarderFingerprint, bobEntity.Subkeys[0].PublicKey.Fingerprint) {
9394
t.Fatalf("invalid forwarder key ID, expected: %x, got: %x", bobEntity.Subkeys[0].PublicKey.Fingerprint, instances[0].ForwarderFingerprint)
9495
}
9596

96-
if bytes.Compare(instances[0].ForwardeeFingerprint, charlesEntity.Subkeys[0].PublicKey.Fingerprint) != 0 {
97+
if !bytes.Equal(instances[0].ForwardeeFingerprint, charlesEntity.Subkeys[0].PublicKey.Fingerprint) {
9798
t.Fatalf("invalid forwardee key ID, expected: %x, got: %x", charlesEntity.Subkeys[0].PublicKey.Fingerprint, instances[0].ForwardeeFingerprint)
9899
}
99100

@@ -123,7 +124,7 @@ func TestForwardingFull(t *testing.T) {
123124
}
124125
dec, err := ioutil.ReadAll(m.decrypted)
125126

126-
if bytes.Compare(dec, plaintext) != 0 {
127+
if !bytes.Equal(dec, plaintext) {
127128
t.Fatal("decrypted does not match original")
128129
}
129130

@@ -139,7 +140,7 @@ func TestForwardingFull(t *testing.T) {
139140

140141
dec, err = ioutil.ReadAll(m.decrypted)
141142

142-
if bytes.Compare(dec, plaintext) != 0 {
143+
if !bytes.Equal(dec, plaintext) {
143144
t.Fatal("forwarded decrypted does not match original")
144145
}
145146

@@ -161,7 +162,7 @@ func TestForwardingFull(t *testing.T) {
161162

162163
dec, err = ioutil.ReadAll(m.decrypted)
163164

164-
if bytes.Compare(dec, plaintext) != 0 {
165+
if !bytes.Equal(dec, plaintext) {
165166
t.Fatal("forwarded decrypted does not match original")
166167
}
167168
}

Diff for: openpgp/keys_test.go

+23-24
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"github.com/ProtonMail/go-crypto/openpgp/eddsa"
2020
"github.com/ProtonMail/go-crypto/openpgp/elgamal"
2121
"github.com/ProtonMail/go-crypto/openpgp/errors"
22-
"github.com/ProtonMail/go-crypto/openpgp/symmetric"
2322
"github.com/ProtonMail/go-crypto/openpgp/internal/algorithm"
2423
"github.com/ProtonMail/go-crypto/openpgp/packet"
2524
"github.com/ProtonMail/go-crypto/openpgp/s2k"
25+
"github.com/ProtonMail/go-crypto/openpgp/symmetric"
2626
)
2727

2828
var hashes = []crypto.Hash{
@@ -1169,7 +1169,7 @@ func TestAddSubkeySerialized(t *testing.T) {
11691169

11701170
func TestAddHMACSubkey(t *testing.T) {
11711171
c := &packet.Config{
1172-
RSABits: 512,
1172+
RSABits: 512,
11731173
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
11741174
}
11751175

@@ -1184,7 +1184,7 @@ func TestAddHMACSubkey(t *testing.T) {
11841184
}
11851185

11861186
buf := bytes.NewBuffer(nil)
1187-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1187+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
11881188
if err := entity.SerializePrivate(w, nil); err != nil {
11891189
t.Errorf("failed to serialize entity: %s", err)
11901190
}
@@ -1201,37 +1201,36 @@ func TestAddHMACSubkey(t *testing.T) {
12011201
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey)
12021202
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey)
12031203

1204-
if bytes.Compare(parsedPrivateKey.Key, generatedPrivateKey.Key) != 0 {
1204+
if !bytes.Equal(parsedPrivateKey.Key, generatedPrivateKey.Key) {
12051205
t.Error("parsed wrong key")
12061206
}
1207-
if bytes.Compare(parsedPublicKey.Key, generatedPrivateKey.Key) != 0 {
1207+
if !bytes.Equal(parsedPublicKey.Key, generatedPrivateKey.Key) {
12081208
t.Error("parsed wrong key in public part")
12091209
}
1210-
if bytes.Compare(generatedPublicKey.Key, generatedPrivateKey.Key) != 0 {
1210+
if !bytes.Equal(generatedPublicKey.Key, generatedPrivateKey.Key) {
12111211
t.Error("generated Public and Private Key differ")
12121212
}
12131213

1214-
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 {
1214+
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) {
12151215
t.Error("parsed wrong hash seed")
12161216
}
12171217

12181218
if parsedPrivateKey.PublicKey.Hash != generatedPrivateKey.PublicKey.Hash {
12191219
t.Error("parsed wrong cipher id")
12201220
}
1221-
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 {
1221+
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) {
12221222
t.Error("parsed wrong binding hash")
12231223
}
12241224
}
12251225

12261226
func TestSerializeSymmetricSubkeyError(t *testing.T) {
1227-
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024})
1227+
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
12281228
if err != nil {
12291229
t.Fatal(err)
12301230
}
12311231

1232-
12331232
buf := bytes.NewBuffer(nil)
1234-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1233+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
12351234

12361235
entity.PrimaryKey.PubKeyAlgo = 100
12371236
err = entity.Serialize(w)
@@ -1248,7 +1247,7 @@ func TestSerializeSymmetricSubkeyError(t *testing.T) {
12481247

12491248
func TestAddAEADSubkey(t *testing.T) {
12501249
c := &packet.Config{
1251-
RSABits: 512,
1250+
RSABits: 512,
12521251
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
12531252
}
12541253
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
@@ -1264,7 +1263,7 @@ func TestAddAEADSubkey(t *testing.T) {
12641263
generatedPrivateKey := entity.Subkeys[1].PrivateKey.PrivateKey.(*symmetric.AEADPrivateKey)
12651264

12661265
buf := bytes.NewBuffer(nil)
1267-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1266+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
12681267
if err := entity.SerializePrivate(w, nil); err != nil {
12691268
t.Errorf("failed to serialize entity: %s", err)
12701269
}
@@ -1280,39 +1279,39 @@ func TestAddAEADSubkey(t *testing.T) {
12801279
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey)
12811280
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey)
12821281

1283-
if bytes.Compare(parsedPrivateKey.Key, generatedPrivateKey.Key) != 0 {
1282+
if !bytes.Equal(parsedPrivateKey.Key, generatedPrivateKey.Key) {
12841283
t.Error("parsed wrong key")
12851284
}
1286-
if bytes.Compare(parsedPublicKey.Key, generatedPrivateKey.Key) != 0 {
1285+
if !bytes.Equal(parsedPublicKey.Key, generatedPrivateKey.Key) {
12871286
t.Error("parsed wrong key in public part")
12881287
}
1289-
if bytes.Compare(generatedPublicKey.Key, generatedPrivateKey.Key) != 0 {
1288+
if !bytes.Equal(generatedPublicKey.Key, generatedPrivateKey.Key) {
12901289
t.Error("generated Public and Private Key differ")
12911290
}
12921291

1293-
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 {
1292+
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) {
12941293
t.Error("parsed wrong hash seed")
12951294
}
12961295

12971296
if parsedPrivateKey.PublicKey.Cipher.Id() != generatedPrivateKey.PublicKey.Cipher.Id() {
12981297
t.Error("parsed wrong cipher id")
12991298
}
1300-
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 {
1299+
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) {
13011300
t.Error("parsed wrong binding hash")
13021301
}
13031302
}
13041303

13051304
func TestNoSymmetricKeySerialized(t *testing.T) {
13061305
aeadConfig := &packet.Config{
1307-
RSABits: 512,
1308-
DefaultHash: crypto.SHA512,
1309-
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
1306+
RSABits: 512,
1307+
DefaultHash: crypto.SHA512,
1308+
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
13101309
DefaultCipher: packet.CipherAES256,
13111310
}
13121311
hmacConfig := &packet.Config{
1313-
RSABits: 512,
1314-
DefaultHash: crypto.SHA512,
1315-
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
1312+
RSABits: 512,
1313+
DefaultHash: crypto.SHA512,
1314+
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
13161315
DefaultCipher: packet.CipherAES256,
13171316
}
13181317
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})

Diff for: openpgp/read_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func TestSymmetricAeadEaxOpenPGPJsMessage(t *testing.T) {
751751
}
752752

753753
// Decrypt with key
754-
var edp = p.(*packet.AEADEncrypted)
754+
edp := p.(*packet.AEADEncrypted)
755755
rc, err := edp.Decrypt(packet.CipherFunction(0), key)
756756
if err != nil {
757757
panic(err)

Diff for: openpgp/write_test.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ func TestNewEntity(t *testing.T) {
262262

263263
func TestEncryptWithAEAD(t *testing.T) {
264264
c := &packet.Config{
265-
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
265+
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
266266
DefaultCipher: packet.CipherAES256,
267267
AEADConfig: &packet.AEADConfig{
268268
DefaultMode: packet.AEADMode(1),
269269
},
270270
}
271-
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024})
271+
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
272272
if err != nil {
273273
t.Fatal(err)
274274
}
@@ -278,8 +278,7 @@ func TestEncryptWithAEAD(t *testing.T) {
278278
t.Fatal(err)
279279
}
280280

281-
var list []*Entity
282-
list = make([]*Entity, 1)
281+
list := make([]*Entity, 1)
283282
list[0] = entity
284283
entityList := EntityList(list)
285284
buf := bytes.NewBuffer(nil)
@@ -304,7 +303,7 @@ func TestEncryptWithAEAD(t *testing.T) {
304303
}
305304
dec, err := ioutil.ReadAll(m.decrypted)
306305

307-
if bytes.Compare(dec, []byte(message)) != 0 {
306+
if !bytes.Equal(dec, []byte(message)) {
308307
t.Error("decrypted does not match original")
309308
}
310309
}
@@ -314,7 +313,7 @@ func TestSignWithHMAC(t *testing.T) {
314313
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
315314
DefaultHash: crypto.SHA512,
316315
}
317-
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024})
316+
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
318317
if err != nil {
319318
t.Fatal(err)
320319
}
@@ -323,8 +322,7 @@ func TestSignWithHMAC(t *testing.T) {
323322
if err != nil {
324323
t.Fatal(err)
325324
}
326-
var list []*Entity
327-
list = make([]*Entity, 1)
325+
list := make([]*Entity, 1)
328326
list[0] = entity
329327
entityList := EntityList(list)
330328

0 commit comments

Comments
 (0)