@@ -19,10 +19,10 @@ import (
19
19
"github.com/ProtonMail/go-crypto/openpgp/eddsa"
20
20
"github.com/ProtonMail/go-crypto/openpgp/elgamal"
21
21
"github.com/ProtonMail/go-crypto/openpgp/errors"
22
- "github.com/ProtonMail/go-crypto/openpgp/symmetric"
23
22
"github.com/ProtonMail/go-crypto/openpgp/internal/algorithm"
24
23
"github.com/ProtonMail/go-crypto/openpgp/packet"
25
24
"github.com/ProtonMail/go-crypto/openpgp/s2k"
25
+ "github.com/ProtonMail/go-crypto/openpgp/symmetric"
26
26
)
27
27
28
28
var hashes = []crypto.Hash {
@@ -1169,7 +1169,7 @@ func TestAddSubkeySerialized(t *testing.T) {
1169
1169
1170
1170
func TestAddHMACSubkey (t * testing.T ) {
1171
1171
c := & packet.Config {
1172
- RSABits : 512 ,
1172
+ RSABits : 512 ,
1173
1173
Algorithm : packet .ExperimentalPubKeyAlgoHMAC ,
1174
1174
}
1175
1175
@@ -1184,7 +1184,7 @@ func TestAddHMACSubkey(t *testing.T) {
1184
1184
}
1185
1185
1186
1186
buf := bytes .NewBuffer (nil )
1187
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1187
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1188
1188
if err := entity .SerializePrivate (w , nil ); err != nil {
1189
1189
t .Errorf ("failed to serialize entity: %s" , err )
1190
1190
}
@@ -1201,37 +1201,36 @@ func TestAddHMACSubkey(t *testing.T) {
1201
1201
generatedPublicKey := entity .Subkeys [1 ].PublicKey .PublicKey .(* symmetric.HMACPublicKey )
1202
1202
parsedPublicKey := key [0 ].Subkeys [1 ].PublicKey .PublicKey .(* symmetric.HMACPublicKey )
1203
1203
1204
- if bytes .Compare (parsedPrivateKey .Key , generatedPrivateKey .Key ) != 0 {
1204
+ if ! bytes .Equal (parsedPrivateKey .Key , generatedPrivateKey .Key ) {
1205
1205
t .Error ("parsed wrong key" )
1206
1206
}
1207
- if bytes .Compare (parsedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1207
+ if ! bytes .Equal (parsedPublicKey .Key , generatedPrivateKey .Key ) {
1208
1208
t .Error ("parsed wrong key in public part" )
1209
1209
}
1210
- if bytes .Compare (generatedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1210
+ if ! bytes .Equal (generatedPublicKey .Key , generatedPrivateKey .Key ) {
1211
1211
t .Error ("generated Public and Private Key differ" )
1212
1212
}
1213
1213
1214
- if bytes .Compare (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) != 0 {
1214
+ if ! bytes .Equal (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) {
1215
1215
t .Error ("parsed wrong hash seed" )
1216
1216
}
1217
1217
1218
1218
if parsedPrivateKey .PublicKey .Hash != generatedPrivateKey .PublicKey .Hash {
1219
1219
t .Error ("parsed wrong cipher id" )
1220
1220
}
1221
- if bytes .Compare (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) != 0 {
1221
+ if ! bytes .Equal (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) {
1222
1222
t .Error ("parsed wrong binding hash" )
1223
1223
}
1224
1224
}
1225
1225
1226
1226
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 })
1228
1228
if err != nil {
1229
1229
t .Fatal (err )
1230
1230
}
1231
1231
1232
-
1233
1232
buf := bytes .NewBuffer (nil )
1234
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1233
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1235
1234
1236
1235
entity .PrimaryKey .PubKeyAlgo = 100
1237
1236
err = entity .Serialize (w )
@@ -1248,7 +1247,7 @@ func TestSerializeSymmetricSubkeyError(t *testing.T) {
1248
1247
1249
1248
func TestAddAEADSubkey (t * testing.T ) {
1250
1249
c := & packet.Config {
1251
- RSABits : 512 ,
1250
+ RSABits : 512 ,
1252
1251
Algorithm : packet .ExperimentalPubKeyAlgoAEAD ,
1253
1252
}
1254
1253
entity ,
err := NewEntity (
"Golang Gopher" ,
"Test Key" ,
"[email protected] " ,
& packet.
Config {
RSABits :
1024 })
@@ -1264,7 +1263,7 @@ func TestAddAEADSubkey(t *testing.T) {
1264
1263
generatedPrivateKey := entity .Subkeys [1 ].PrivateKey .PrivateKey .(* symmetric.AEADPrivateKey )
1265
1264
1266
1265
buf := bytes .NewBuffer (nil )
1267
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1266
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1268
1267
if err := entity .SerializePrivate (w , nil ); err != nil {
1269
1268
t .Errorf ("failed to serialize entity: %s" , err )
1270
1269
}
@@ -1280,39 +1279,39 @@ func TestAddAEADSubkey(t *testing.T) {
1280
1279
generatedPublicKey := entity .Subkeys [1 ].PublicKey .PublicKey .(* symmetric.AEADPublicKey )
1281
1280
parsedPublicKey := key [0 ].Subkeys [1 ].PublicKey .PublicKey .(* symmetric.AEADPublicKey )
1282
1281
1283
- if bytes .Compare (parsedPrivateKey .Key , generatedPrivateKey .Key ) != 0 {
1282
+ if ! bytes .Equal (parsedPrivateKey .Key , generatedPrivateKey .Key ) {
1284
1283
t .Error ("parsed wrong key" )
1285
1284
}
1286
- if bytes .Compare (parsedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1285
+ if ! bytes .Equal (parsedPublicKey .Key , generatedPrivateKey .Key ) {
1287
1286
t .Error ("parsed wrong key in public part" )
1288
1287
}
1289
- if bytes .Compare (generatedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1288
+ if ! bytes .Equal (generatedPublicKey .Key , generatedPrivateKey .Key ) {
1290
1289
t .Error ("generated Public and Private Key differ" )
1291
1290
}
1292
1291
1293
- if bytes .Compare (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) != 0 {
1292
+ if ! bytes .Equal (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) {
1294
1293
t .Error ("parsed wrong hash seed" )
1295
1294
}
1296
1295
1297
1296
if parsedPrivateKey .PublicKey .Cipher .Id () != generatedPrivateKey .PublicKey .Cipher .Id () {
1298
1297
t .Error ("parsed wrong cipher id" )
1299
1298
}
1300
- if bytes .Compare (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) != 0 {
1299
+ if ! bytes .Equal (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) {
1301
1300
t .Error ("parsed wrong binding hash" )
1302
1301
}
1303
1302
}
1304
1303
1305
1304
func TestNoSymmetricKeySerialized (t * testing.T ) {
1306
1305
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 ,
1310
1309
DefaultCipher : packet .CipherAES256 ,
1311
1310
}
1312
1311
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 ,
1316
1315
DefaultCipher : packet .CipherAES256 ,
1317
1316
}
1318
1317
entity ,
err := NewEntity (
"Golang Gopher" ,
"Test Key" ,
"[email protected] " ,
& packet.
Config {
RSABits :
1024 })
0 commit comments