add ed25519 tests
This adds the tests for the ed25519 keys.
This commit is contained in:
parent
2cfb28a0ce
commit
f004403281
|
@ -1,6 +1,7 @@
|
||||||
package pki
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
|
@ -24,7 +25,10 @@ func RunMarshalTest(pkType string, pe Pemmer, label string, t *testing.T) ([]byt
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
block, _ := pem.Decode(marshPem)
|
buf := &bytes.Buffer{}
|
||||||
|
marshPem.WriteTo(buf)
|
||||||
|
|
||||||
|
block, _ := pem.Decode(buf.Bytes())
|
||||||
if block.Type != label {
|
if block.Type != label {
|
||||||
t.Errorf("%s: marshalled pem wrong: %s", pkType, err)
|
t.Errorf("%s: marshalled pem wrong: %s", pkType, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -53,6 +57,7 @@ func TestEcdsaFunctions(t *testing.T) {
|
||||||
pk, err := NewPrivateKeyEcdsa(elliptic.P521())
|
pk, err := NewPrivateKeyEcdsa(elliptic.P521())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("ecdsa: creating private key failed: %s", err)
|
t.Errorf("ecdsa: creating private key failed: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockBytes, err := RunMarshalTest("ecdsa", pk, PemLabelEcdsa, t)
|
blockBytes, err := RunMarshalTest("ecdsa", pk, PemLabelEcdsa, t)
|
||||||
|
@ -63,6 +68,7 @@ func TestEcdsaFunctions(t *testing.T) {
|
||||||
pk, err = LoadPrivateKeyEcdsa(blockBytes)
|
pk, err = LoadPrivateKeyEcdsa(blockBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("ecdsa: pem content wrong: %s", err)
|
t.Errorf("ecdsa: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockBytes, err = RunMarshalTest("ecdsa-public", pk.Public(), PemLabelPublic, t)
|
blockBytes, err = RunMarshalTest("ecdsa-public", pk.Public(), PemLabelPublic, t)
|
||||||
|
@ -73,6 +79,7 @@ func TestEcdsaFunctions(t *testing.T) {
|
||||||
pu, err := LoadPublicKeyEcdsa(blockBytes)
|
pu, err := LoadPublicKeyEcdsa(blockBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("ecdsa-public: pem content wrong: %s", err)
|
t.Errorf("ecdsa-public: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RunPrivateKeyTests("ecdsa", pk, pu, t)
|
RunPrivateKeyTests("ecdsa", pk, pu, t)
|
||||||
|
@ -83,6 +90,7 @@ func TestRsaFunctions(t *testing.T) {
|
||||||
pk, err := NewPrivateKeyRsa(2048)
|
pk, err := NewPrivateKeyRsa(2048)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("rsa: creating private key failed: %s", err)
|
t.Errorf("rsa: creating private key failed: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockBytes, err := RunMarshalTest("rsa", pk, PemLabelRsa, t)
|
blockBytes, err := RunMarshalTest("rsa", pk, PemLabelRsa, t)
|
||||||
|
@ -93,6 +101,7 @@ func TestRsaFunctions(t *testing.T) {
|
||||||
pk, err = LoadPrivateKeyRsa(blockBytes)
|
pk, err = LoadPrivateKeyRsa(blockBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("rsa: pem content wrong: %s", err)
|
t.Errorf("rsa: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockBytes, err = RunMarshalTest("rsa-public", pk.Public(), PemLabelPublic, t)
|
blockBytes, err = RunMarshalTest("rsa-public", pk.Public(), PemLabelPublic, t)
|
||||||
|
@ -103,7 +112,41 @@ func TestRsaFunctions(t *testing.T) {
|
||||||
pu, err := LoadPublicKeyRsa(blockBytes)
|
pu, err := LoadPublicKeyRsa(blockBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("rsa-public: pem content wrong: %s", err)
|
t.Errorf("rsa-public: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RunPrivateKeyTests("rsa", pk, pu, t)
|
RunPrivateKeyTests("rsa", pk, pu, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test rsa private key functions
|
||||||
|
func TestEd25519Functions(t *testing.T) {
|
||||||
|
pk, err := NewPrivateKeyEd25519()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("ed25519: creating private key failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
blockBytes, err := RunMarshalTest("ed25519", pk, PemLabelEd25519, t)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pk, err = LoadPrivateKeyEd25519(blockBytes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("ed25519: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
blockBytes, err = RunMarshalTest("ed25519-public", pk.Public(), PemLabelPublic, t)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pu, err := LoadPublicKeyEd25519(blockBytes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("ed25519-public: pem content wrong: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RunPrivateKeyTests("ed25519", pk, pu, t)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue