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