diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2017-01-09 17:21:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-09 17:21:11 +0000 |
commit | 3e0a562f6b59075c9d7718b3155501e0be491767 (patch) | |
tree | b82061b8a2af25fbc13f6f9792d42ed7a2ed9d54 /client/keys_test.go | |
parent | 6dfe350cb5eefde3a99374d14c083d1906717ddd (diff) | |
parent | fc190076448ebf1710910a89b584857cbc89d159 (diff) |
Merge pull request #39 from nsheridan/opts2
Simplify key generation
Diffstat (limited to 'client/keys_test.go')
-rw-r--r-- | client/keys_test.go | 52 |
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) + } +} |