-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ import ( | |
"github.com/ProtonMail/go-crypto/openpgp/eddsa" | ||
"github.com/ProtonMail/go-crypto/openpgp/elgamal" | ||
"github.com/ProtonMail/go-crypto/openpgp/errors" | ||
"github.com/ProtonMail/go-crypto/openpgp/symmetric" | ||
"github.com/ProtonMail/go-crypto/openpgp/internal/algorithm" | ||
"github.com/ProtonMail/go-crypto/openpgp/packet" | ||
"github.com/ProtonMail/go-crypto/openpgp/s2k" | ||
"github.com/ProtonMail/go-crypto/openpgp/symmetric" | ||
) | ||
|
||
var hashes = []crypto.Hash{ | ||
|
@@ -1172,7 +1172,7 @@ func TestAddSubkeySerialized(t *testing.T) { | |
|
||
func TestAddHMACSubkey(t *testing.T) { | ||
c := &packet.Config{ | ||
RSABits: 512, | ||
RSABits: 512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoHMAC, | ||
} | ||
|
||
|
@@ -1187,7 +1187,7 @@ func TestAddHMACSubkey(t *testing.T) { | |
} | ||
|
||
buf := bytes.NewBuffer(nil) | ||
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil) | ||
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil) | ||
if err := entity.SerializePrivate(w, nil); err != nil { | ||
t.Errorf("failed to serialize entity: %s", err) | ||
} | ||
|
@@ -1204,37 +1204,36 @@ func TestAddHMACSubkey(t *testing.T) { | |
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey) | ||
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.HMACPublicKey) | ||
|
||
if bytes.Compare(parsedPrivateKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.Key, generatedPrivateKey.Key) { | ||
t.Error("parsed wrong key") | ||
} | ||
if bytes.Compare(parsedPublicKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(parsedPublicKey.Key, generatedPrivateKey.Key) { | ||
t.Error("parsed wrong key in public part") | ||
} | ||
if bytes.Compare(generatedPublicKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(generatedPublicKey.Key, generatedPrivateKey.Key) { | ||
t.Error("generated Public and Private Key differ") | ||
} | ||
|
||
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) { | ||
t.Error("parsed wrong hash seed") | ||
} | ||
|
||
if parsedPrivateKey.PublicKey.Hash != generatedPrivateKey.PublicKey.Hash { | ||
t.Error("parsed wrong cipher id") | ||
} | ||
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) { | ||
t.Error("parsed wrong binding hash") | ||
} | ||
} | ||
|
||
func TestSerializeSymmetricSubkeyError(t *testing.T) { | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024}) | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
|
||
buf := bytes.NewBuffer(nil) | ||
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil) | ||
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil) | ||
|
||
entity.PrimaryKey.PubKeyAlgo = 100 | ||
err = entity.Serialize(w) | ||
|
@@ -1251,7 +1250,7 @@ func TestSerializeSymmetricSubkeyError(t *testing.T) { | |
|
||
func TestAddAEADSubkey(t *testing.T) { | ||
c := &packet.Config{ | ||
RSABits: 512, | ||
RSABits: 512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoAEAD, | ||
} | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024}) | ||
|
@@ -1267,7 +1266,7 @@ func TestAddAEADSubkey(t *testing.T) { | |
generatedPrivateKey := entity.Subkeys[1].PrivateKey.PrivateKey.(*symmetric.AEADPrivateKey) | ||
|
||
buf := bytes.NewBuffer(nil) | ||
w, _ := armor.Encode(buf , "PGP PRIVATE KEY BLOCK", nil) | ||
w, _ := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil) | ||
if err := entity.SerializePrivate(w, nil); err != nil { | ||
t.Errorf("failed to serialize entity: %s", err) | ||
} | ||
|
@@ -1283,39 +1282,39 @@ func TestAddAEADSubkey(t *testing.T) { | |
generatedPublicKey := entity.Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey) | ||
parsedPublicKey := key[0].Subkeys[1].PublicKey.PublicKey.(*symmetric.AEADPublicKey) | ||
|
||
if bytes.Compare(parsedPrivateKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.Key, generatedPrivateKey.Key) { | ||
t.Error("parsed wrong key") | ||
} | ||
if bytes.Compare(parsedPublicKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(parsedPublicKey.Key, generatedPrivateKey.Key) { | ||
t.Error("parsed wrong key in public part") | ||
} | ||
if bytes.Compare(generatedPublicKey.Key, generatedPrivateKey.Key) != 0 { | ||
if !bytes.Equal(generatedPublicKey.Key, generatedPrivateKey.Key) { | ||
t.Error("generated Public and Private Key differ") | ||
} | ||
|
||
if bytes.Compare(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.HashSeed[:], generatedPrivateKey.HashSeed[:]) { | ||
t.Error("parsed wrong hash seed") | ||
} | ||
|
||
if parsedPrivateKey.PublicKey.Cipher.Id() != generatedPrivateKey.PublicKey.Cipher.Id() { | ||
t.Error("parsed wrong cipher id") | ||
} | ||
if bytes.Compare(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) != 0 { | ||
if !bytes.Equal(parsedPrivateKey.PublicKey.BindingHash[:], generatedPrivateKey.PublicKey.BindingHash[:]) { | ||
t.Error("parsed wrong binding hash") | ||
} | ||
} | ||
|
||
func TestNoSymmetricKeySerialized(t *testing.T) { | ||
aeadConfig := &packet.Config{ | ||
RSABits: 512, | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoAEAD, | ||
RSABits: 512, | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoAEAD, | ||
DefaultCipher: packet.CipherAES256, | ||
} | ||
hmacConfig := &packet.Config{ | ||
RSABits: 512, | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoHMAC, | ||
RSABits: 512, | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: packet.ExperimentalPubKeyAlgoHMAC, | ||
DefaultCipher: packet.CipherAES256, | ||
} | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,13 +266,13 @@ func TestNewEntity(t *testing.T) { | |
|
||
func TestEncryptWithAEAD(t *testing.T) { | ||
c := &packet.Config{ | ||
Algorithm: packet.ExperimentalPubKeyAlgoAEAD, | ||
Algorithm: packet.ExperimentalPubKeyAlgoAEAD, | ||
DefaultCipher: packet.CipherAES256, | ||
AEADConfig: &packet.AEADConfig{ | ||
DefaultMode: packet.AEADMode(1), | ||
}, | ||
} | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024}) | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -282,8 +282,7 @@ func TestEncryptWithAEAD(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
var list []*Entity | ||
list = make([]*Entity, 1) | ||
list := make([]*Entity, 1) | ||
list[0] = entity | ||
entityList := EntityList(list) | ||
buf := bytes.NewBuffer(nil) | ||
|
@@ -308,7 +307,7 @@ func TestEncryptWithAEAD(t *testing.T) { | |
} | ||
dec, err := ioutil.ReadAll(m.decrypted) | ||
|
||
if bytes.Compare(dec, []byte(message)) != 0 { | ||
if !bytes.Equal(dec, []byte(message)) { | ||
t.Error("decrypted does not match original") | ||
} | ||
} | ||
|
@@ -318,7 +317,7 @@ func TestSignWithHMAC(t *testing.T) { | |
Algorithm: packet.ExperimentalPubKeyAlgoHMAC, | ||
DefaultHash: crypto.SHA512, | ||
} | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{ RSABits: 1024}) | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", &packet.Config{RSABits: 1024}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -327,8 +326,7 @@ func TestSignWithHMAC(t *testing.T) { | |
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var list []*Entity | ||
list = make([]*Entity, 1) | ||
list := make([]*Entity, 1) | ||
list[0] = entity | ||
entityList := EntityList(list) | ||
|
||
|