Skip to content

Commit 4017cb3

Browse files
committed
fix: Address warnings
1 parent fcee26d commit 4017cb3

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

openpgp/forwarding.go

Lines changed: 2 additions & 2 deletions
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

openpgp/forwarding_test.go

Lines changed: 9 additions & 8 deletions
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
}

openpgp/keys_test.go

Lines changed: 23 additions & 24 deletions
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{
@@ -1172,7 +1172,7 @@ func TestAddSubkeySerialized(t *testing.T) {
11721172

11731173
func TestAddHMACSubkey(t *testing.T) {
11741174
c := &packet.Config{
1175-
RSABits: 512,
1175+
RSABits: 512,
11761176
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
11771177
}
11781178

@@ -1187,7 +1187,7 @@ func TestAddHMACSubkey(t *testing.T) {
11871187
}
11881188

11891189
buf := bytes.NewBuffer(nil)
1190-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1190+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
11911191
if err := entity.SerializePrivate(w, nil); err != nil {
11921192
t.Errorf("failed to serialize entity: %s", err)
11931193
}
@@ -1204,37 +1204,36 @@ func TestAddHMACSubkey(t *testing.T) {
12041204
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey)
12051205
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey)
12061206

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

1217-
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 {
1217+
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) {
12181218
t.Error("parsed wrong hash seed")
12191219
}
12201220

12211221
if parsedPrivateKey.PublicKey.Hash != generatedPrivateKey.PublicKey.Hash {
12221222
t.Error("parsed wrong cipher id")
12231223
}
1224-
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 {
1224+
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) {
12251225
t.Error("parsed wrong binding hash")
12261226
}
12271227
}
12281228

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

1235-
12361235
buf := bytes.NewBuffer(nil)
1237-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1236+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
12381237

12391238
entity.PrimaryKey.PubKeyAlgo = 100
12401239
err = entity.Serialize(w)
@@ -1251,7 +1250,7 @@ func TestSerializeSymmetricSubkeyError(t *testing.T) {
12511250

12521251
func TestAddAEADSubkey(t *testing.T) {
12531252
c := &packet.Config{
1254-
RSABits: 512,
1253+
RSABits: 512,
12551254
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
12561255
}
12571256
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
@@ -1267,7 +1266,7 @@ func TestAddAEADSubkey(t *testing.T) {
12671266
generatedPrivateKey := entity.Subkeys[1].PrivateKey.PrivateKey.(*symmetric.AEADPrivateKey)
12681267

12691268
buf := bytes.NewBuffer(nil)
1270-
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil)
1269+
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
12711270
if err := entity.SerializePrivate(w, nil); err != nil {
12721271
t.Errorf("failed to serialize entity: %s", err)
12731272
}
@@ -1283,39 +1282,39 @@ func TestAddAEADSubkey(t *testing.T) {
12831282
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey)
12841283
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey)
12851284

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

1296-
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 {
1295+
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) {
12971296
t.Error("parsed wrong hash seed")
12981297
}
12991298

13001299
if parsedPrivateKey.PublicKey.Cipher.Id() != generatedPrivateKey.PublicKey.Cipher.Id() {
13011300
t.Error("parsed wrong cipher id")
13021301
}
1303-
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 {
1302+
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) {
13041303
t.Error("parsed wrong binding hash")
13051304
}
13061305
}
13071306

13081307
func TestNoSymmetricKeySerialized(t *testing.T) {
13091308
aeadConfig := &packet.Config{
1310-
RSABits: 512,
1311-
DefaultHash: crypto.SHA512,
1312-
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
1309+
RSABits: 512,
1310+
DefaultHash: crypto.SHA512,
1311+
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
13131312
DefaultCipher: packet.CipherAES256,
13141313
}
13151314
hmacConfig := &packet.Config{
1316-
RSABits: 512,
1317-
DefaultHash: crypto.SHA512,
1318-
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
1315+
RSABits: 512,
1316+
DefaultHash: crypto.SHA512,
1317+
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
13191318
DefaultCipher: packet.CipherAES256,
13201319
}
13211320
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})

openpgp/read_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ func TestSymmetricAeadEaxOpenPGPJsMessage(t *testing.T) {
757757
}
758758

759759
// Decrypt with key
760-
var edp = p.(*packet.AEADEncrypted)
760+
edp := p.(*packet.AEADEncrypted)
761761
rc, err := edp.Decrypt(packet.CipherFunction(0), key)
762762
if err != nil {
763763
panic(err)

openpgp/write_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ func TestNewEntity(t *testing.T) {
266266

267267
func TestEncryptWithAEAD(t *testing.T) {
268268
c := &packet.Config{
269-
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
269+
Algorithm: packet.ExperimentalPubKeyAlgoAEAD,
270270
DefaultCipher: packet.CipherAES256,
271271
AEADConfig: &packet.AEADConfig{
272272
DefaultMode: packet.AEADMode(1),
273273
},
274274
}
275-
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024})
275+
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
276276
if err != nil {
277277
t.Fatal(err)
278278
}
@@ -282,8 +282,7 @@ func TestEncryptWithAEAD(t *testing.T) {
282282
t.Fatal(err)
283283
}
284284

285-
var list []*Entity
286-
list = make([]*Entity, 1)
285+
list := make([]*Entity, 1)
287286
list[0] = entity
288287
entityList := EntityList(list)
289288
buf := bytes.NewBuffer(nil)
@@ -308,7 +307,7 @@ func TestEncryptWithAEAD(t *testing.T) {
308307
}
309308
dec, err := ioutil.ReadAll(m.decrypted)
310309

311-
if bytes.Compare(dec, []byte(message)) != 0 {
310+
if !bytes.Equal(dec, []byte(message)) {
312311
t.Error("decrypted does not match original")
313312
}
314313
}
@@ -318,7 +317,7 @@ func TestSignWithHMAC(t *testing.T) {
318317
Algorithm: packet.ExperimentalPubKeyAlgoHMAC,
319318
DefaultHash: crypto.SHA512,
320319
}
321-
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024})
320+
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024})
322321
if err != nil {
323322
t.Fatal(err)
324323
}
@@ -327,8 +326,7 @@ func TestSignWithHMAC(t *testing.T) {
327326
if err != nil {
328327
t.Fatal(err)
329328
}
330-
var list []*Entity
331-
list = make([]*Entity, 1)
329+
list := make([]*Entity, 1)
332330
list[0] = entity
333331
entityList := EntityList(list)
334332

0 commit comments

Comments
 (0)