master
go 49 lines 1.1 KB
Raw
1 package config
2
3 import (
4 "bytes"
5 "testing"
6
7 "github.com/ipfs/kubo/core/coreiface/options"
8 crypto_pb "github.com/libp2p/go-libp2p/core/crypto/pb"
9 )
10
11 func TestCreateIdentity(t *testing.T) {
12 writer := bytes.NewBuffer(nil)
13 id, err := CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.Ed25519Key)})
14 if err != nil {
15 t.Fatal(err)
16 }
17 pk, err := id.DecodePrivateKey("")
18 if err != nil {
19 t.Fatal(err)
20 }
21 if pk.Type() != crypto_pb.KeyType_Ed25519 {
22 t.Fatal("unexpected type:", pk.Type())
23 }
24
25 id, err = CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.RSAKey)})
26 if err != nil {
27 t.Fatal(err)
28 }
29 pk, err = id.DecodePrivateKey("")
30 if err != nil {
31 t.Fatal(err)
32 }
33 if pk.Type() != crypto_pb.KeyType_RSA {
34 t.Fatal("unexpected type:", pk.Type())
35 }
36 }
37
38 func TestCreateIdentityOptions(t *testing.T) {
39 var w bytes.Buffer
40
41 // ed25519 keys with bit size must fail.
42 _, err := CreateIdentity(&w, []options.KeyGenerateOption{
43 options.Key.Type(options.Ed25519Key),
44 options.Key.Size(2048),
45 })
46 if err == nil {
47 t.Errorf("ed25519 keys cannot have a custom bit size")
48 }
49 }