Skip to content

Commit

Permalink
Add read-write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wussler committed May 17, 2023
1 parent eea5d0b commit 3d33cfd
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 9 deletions.
6 changes: 6 additions & 0 deletions openpgp/keys_v6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ func TestGeneratePqKey(t *testing.T) {
DefaultHash: crypto.SHA512,
Algorithm: algo,
V6Keys: true,
AEADConfig: &packet.AEADConfig {
DefaultMode: packet.AEADModeOCB,
},
Time: func() time.Time {
parsed, _ := time.Parse("2006-01-02", "2013-07-01")
return parsed
Expand Down Expand Up @@ -359,6 +362,9 @@ func TestAddKyberSubkey(t *testing.T) {
DefaultHash: crypto.SHA512,
Algorithm: algo,
V6Keys: true,
AEADConfig: &packet.AEADConfig{
DefaultMode: packet.AEADModeOCB,
},
Time: func() time.Time {
parsed, _ := time.Parse("2006-01-02", "2013-07-01")
return parsed
Expand Down
17 changes: 17 additions & 0 deletions openpgp/read_write_test_data.go

Large diffs are not rendered by default.

118 changes: 109 additions & 9 deletions openpgp/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,37 +428,129 @@ func TestSymmetricEncryptionV5RandomizeSlow(t *testing.T) {
var testEncryptionTests = []struct {
keyRingHex string
isSigned bool
okV4 bool
okV6 bool
}{
{
testKeys1And2PrivateHex,
false,
true,
true,
},
{
testKeys1And2PrivateHex,
true,
true,
true,
},
{
dsaElGamalTestKeysHex,
false,
true,
false,
},
{
dsaElGamalTestKeysHex,
true,
true,
false,
},
{
dilithium3Ed25519Kyber768X25519PrivateHex,
false,
false,
true,
},
{
dilithium3Ed25519Kyber768X25519PrivateHex,
true,
false,
true,
},
{
dilithium5Ed448Kyber1024X448PrivateHex,
false,
false,
true,
},
{
dilithium5Ed448Kyber1024X448PrivateHex,
true,
false,
true,
},
{
dilithium3P256Kyber768P245PrivateHex,
false,
false,
true,
},
{
dilithium3P256Kyber768P245PrivateHex,
true,
false,
true,
},
{
dilithium5P384_Kyber1024P384PrivateHex,
false,
false,
true,
},
{
dilithium5P384_Kyber1024P384PrivateHex,
true,
false,
true,
},
{
dilithium3Brainpool256Kyber786Brainpool256PrivateHex,
false,
false,
true,
},
{
dilithium3Brainpool256Kyber786Brainpool256PrivateHex,
true,
false,
true,
},
{
dilithium5Brainpool384Kyber1024Brainpool384PrivateHex,
false,
false,
true,
},
{
dilithium5Brainpool384Kyber1024Brainpool384PrivateHex,
true,
false,
true,
},
{
sphincsPlusSha2Kyber1024X448PrivateHex,
false,
false,
true,
},
{
sphincsPlusSha2Kyber1024X448PrivateHex,
true,
false,
true,
},
{
sphincsPlusShakeKyber1024X448PrivateHex,
false,
false,
true,
},
{
sphincsPlusShakeKyber1024X448PrivateHex,
true,
false,
true,
},
// Broken as it needs v5 PKESK
//{
// eddsaKyber768X25519PrivateHex,
// false,
//},
//{
// eddsaKyber768X25519PrivateHex,
// true,
//},
}

func TestEncryption(t *testing.T) {
Expand Down Expand Up @@ -517,6 +609,14 @@ func TestEncryption(t *testing.T) {
continue
}

if !test.okV4 && config.AEAD() == nil {
// PQC is not allowed with v6
if err == nil {
t.Errorf("#%d: no error when encrypting with forbidden v4 packet", i)
}
continue
}

if err != nil {
t.Errorf("#%d: error in Encrypt: %s", i, err)
continue
Expand Down

0 comments on commit 3d33cfd

Please sign in to comment.