aboutsummaryrefslogtreecommitdiff
path: root/client/keys_test.go
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2017-01-03 23:34:47 +0000
committerNiall Sheridan <nsheridan@gmail.com>2017-01-04 00:57:27 +0000
commita4b5776500b1250b61c3dafd17e464fdf3f3aae8 (patch)
tree024698333eea9664cb29f7f06f5fb58e244fba6e /client/keys_test.go
parent8066efd45861e7c024fc1daabc6d002266a527e7 (diff)
Simplify key generation
Use functions to build key generation options. Make it entirely optional.
Diffstat (limited to 'client/keys_test.go')
-rw-r--r--client/keys_test.go52
1 files changed, 46 insertions, 6 deletions
diff --git a/client/keys_test.go b/client/keys_test.go
index d98a982..6a69492 100644
--- a/client/keys_test.go
+++ b/client/keys_test.go
@@ -1,23 +1,30 @@
package client
import (
+ "crypto/rsa"
"reflect"
"testing"
+
+ "golang.org/x/crypto/ed25519"
)
func TestGenerateKeys(t *testing.T) {
var tests = []struct {
- key string
- size int
- want string
+ keytype string
+ keysize int
+ want string
}{
- {"ecdsa", 256, "*ecdsa.PrivateKey"},
{"rsa", 1024, "*rsa.PrivateKey"},
- {"ed25519", 256, "*ed25519.PrivateKey"},
+ {"rsa", 0, "*rsa.PrivateKey"},
+ {"ecdsa", 0, "*ecdsa.PrivateKey"},
+ {"ecdsa", 384, "*ecdsa.PrivateKey"},
+ {"ed25519", 0, "*ed25519.PrivateKey"},
}
for _, tst := range tests {
- k, _, err := GenerateKey(tst.key, tst.size)
+ var k Key
+ var err error
+ k, _, err = GenerateKey(KeyType(tst.keytype), KeySize(tst.keysize))
if err != nil {
t.Error(err)
}
@@ -26,3 +33,36 @@ func TestGenerateKeys(t *testing.T) {
}
}
}
+
+func TestDefaultOptions(t *testing.T) {
+ k, _, err := GenerateKey()
+ if err != nil {
+ t.Error(err)
+ }
+ _, ok := k.(*rsa.PrivateKey)
+ if !ok {
+ t.Errorf("Unexpected key type %T, wanted *rsa.PrivateKey", k)
+ }
+}
+
+func TestGenerateKeyType(t *testing.T) {
+ k, _, err := GenerateKey(KeyType("ed25519"))
+ if err != nil {
+ t.Error(err)
+ }
+ _, ok := k.(*ed25519.PrivateKey)
+ if !ok {
+ t.Errorf("Unexpected key type %T, wanted *ed25519.PrivateKey", k)
+ }
+}
+
+func TestGenerateKeySize(t *testing.T) {
+ k, _, err := GenerateKey(KeySize(1024))
+ if err != nil {
+ t.Error(err)
+ }
+ _, ok := k.(*rsa.PrivateKey)
+ if !ok {
+ t.Errorf("Unexpected key type %T, wanted *rsa.PrivateKey", k)
+ }
+}