@@ -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 {
@@ -1172,7 +1172,7 @@ func TestAddSubkeySerialized(t *testing.T) {
1172
1172
1173
1173
func TestAddHMACSubkey (t * testing.T ) {
1174
1174
c := & packet.Config {
1175
- RSABits : 512 ,
1175
+ RSABits : 512 ,
1176
1176
Algorithm : packet .ExperimentalPubKeyAlgoHMAC ,
1177
1177
}
1178
1178
@@ -1187,7 +1187,7 @@ func TestAddHMACSubkey(t *testing.T) {
1187
1187
}
1188
1188
1189
1189
buf := bytes .NewBuffer (nil )
1190
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1190
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1191
1191
if err := entity .SerializePrivate (w , nil ); err != nil {
1192
1192
t .Errorf ("failed to serialize entity: %s" , err )
1193
1193
}
@@ -1204,37 +1204,36 @@ func TestAddHMACSubkey(t *testing.T) {
1204
1204
generatedPublicKey := entity .Subkeys [1 ].PublicKey .PublicKey .(* symmetric.HMACPublicKey )
1205
1205
parsedPublicKey := key [0 ].Subkeys [1 ].PublicKey .PublicKey .(* symmetric.HMACPublicKey )
1206
1206
1207
- if bytes .Compare (parsedPrivateKey .Key , generatedPrivateKey .Key ) != 0 {
1207
+ if ! bytes .Equal (parsedPrivateKey .Key , generatedPrivateKey .Key ) {
1208
1208
t .Error ("parsed wrong key" )
1209
1209
}
1210
- if bytes .Compare (parsedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1210
+ if ! bytes .Equal (parsedPublicKey .Key , generatedPrivateKey .Key ) {
1211
1211
t .Error ("parsed wrong key in public part" )
1212
1212
}
1213
- if bytes .Compare (generatedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1213
+ if ! bytes .Equal (generatedPublicKey .Key , generatedPrivateKey .Key ) {
1214
1214
t .Error ("generated Public and Private Key differ" )
1215
1215
}
1216
1216
1217
- if bytes .Compare (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) != 0 {
1217
+ if ! bytes .Equal (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) {
1218
1218
t .Error ("parsed wrong hash seed" )
1219
1219
}
1220
1220
1221
1221
if parsedPrivateKey .PublicKey .Hash != generatedPrivateKey .PublicKey .Hash {
1222
1222
t .Error ("parsed wrong cipher id" )
1223
1223
}
1224
- if bytes .Compare (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) != 0 {
1224
+ if ! bytes .Equal (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) {
1225
1225
t .Error ("parsed wrong binding hash" )
1226
1226
}
1227
1227
}
1228
1228
1229
1229
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 })
1231
1231
if err != nil {
1232
1232
t .Fatal (err )
1233
1233
}
1234
1234
1235
-
1236
1235
buf := bytes .NewBuffer (nil )
1237
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1236
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1238
1237
1239
1238
entity .PrimaryKey .PubKeyAlgo = 100
1240
1239
err = entity .Serialize (w )
@@ -1251,7 +1250,7 @@ func TestSerializeSymmetricSubkeyError(t *testing.T) {
1251
1250
1252
1251
func TestAddAEADSubkey (t * testing.T ) {
1253
1252
c := & packet.Config {
1254
- RSABits : 512 ,
1253
+ RSABits : 512 ,
1255
1254
Algorithm : packet .ExperimentalPubKeyAlgoAEAD ,
1256
1255
}
1257
1256
entity ,
err := NewEntity (
"Golang Gopher" ,
"Test Key" ,
"[email protected] " ,
& packet.
Config {
RSABits :
1024 })
@@ -1267,7 +1266,7 @@ func TestAddAEADSubkey(t *testing.T) {
1267
1266
generatedPrivateKey := entity .Subkeys [1 ].PrivateKey .PrivateKey .(* symmetric.AEADPrivateKey )
1268
1267
1269
1268
buf := bytes .NewBuffer (nil )
1270
- w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1269
+ w , _ := armor .Encode (buf , "PGP PRIVATE KEY BLOCK" , nil )
1271
1270
if err := entity .SerializePrivate (w , nil ); err != nil {
1272
1271
t .Errorf ("failed to serialize entity: %s" , err )
1273
1272
}
@@ -1283,39 +1282,39 @@ func TestAddAEADSubkey(t *testing.T) {
1283
1282
generatedPublicKey := entity .Subkeys [1 ].PublicKey .PublicKey .(* symmetric.AEADPublicKey )
1284
1283
parsedPublicKey := key [0 ].Subkeys [1 ].PublicKey .PublicKey .(* symmetric.AEADPublicKey )
1285
1284
1286
- if bytes .Compare (parsedPrivateKey .Key , generatedPrivateKey .Key ) != 0 {
1285
+ if ! bytes .Equal (parsedPrivateKey .Key , generatedPrivateKey .Key ) {
1287
1286
t .Error ("parsed wrong key" )
1288
1287
}
1289
- if bytes .Compare (parsedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1288
+ if ! bytes .Equal (parsedPublicKey .Key , generatedPrivateKey .Key ) {
1290
1289
t .Error ("parsed wrong key in public part" )
1291
1290
}
1292
- if bytes .Compare (generatedPublicKey .Key , generatedPrivateKey .Key ) != 0 {
1291
+ if ! bytes .Equal (generatedPublicKey .Key , generatedPrivateKey .Key ) {
1293
1292
t .Error ("generated Public and Private Key differ" )
1294
1293
}
1295
1294
1296
- if bytes .Compare (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) != 0 {
1295
+ if ! bytes .Equal (parsedPrivateKey .HashSeed [:], generatedPrivateKey .HashSeed [:]) {
1297
1296
t .Error ("parsed wrong hash seed" )
1298
1297
}
1299
1298
1300
1299
if parsedPrivateKey .PublicKey .Cipher .Id () != generatedPrivateKey .PublicKey .Cipher .Id () {
1301
1300
t .Error ("parsed wrong cipher id" )
1302
1301
}
1303
- if bytes .Compare (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) != 0 {
1302
+ if ! bytes .Equal (parsedPrivateKey .PublicKey .BindingHash [:], generatedPrivateKey .PublicKey .BindingHash [:]) {
1304
1303
t .Error ("parsed wrong binding hash" )
1305
1304
}
1306
1305
}
1307
1306
1308
1307
func TestNoSymmetricKeySerialized (t * testing.T ) {
1309
1308
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 ,
1313
1312
DefaultCipher : packet .CipherAES256 ,
1314
1313
}
1315
1314
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 ,
1319
1318
DefaultCipher : packet .CipherAES256 ,
1320
1319
}
1321
1320
entity ,
err := NewEntity (
"Golang Gopher" ,
"Test Key" ,
"[email protected] " ,
& packet.
Config {
RSABits :
1024 })
0 commit comments