forked from libp2p/go-libp2p-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_test.go
42 lines (36 loc) · 820 Bytes
/
sign_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
package pubsub
import (
"testing"
pb "github.com/libp2p/go-libp2p-pubsub/pb"
crypto "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
)
func TestSigning(t *testing.T) {
privk, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048)
if err != nil {
t.Fatal(err)
}
testSignVerify(t, privk)
privk, _, err = crypto.GenerateKeyPair(crypto.Ed25519, 0)
if err != nil {
t.Fatal(err)
}
testSignVerify(t, privk)
}
func testSignVerify(t *testing.T, privk crypto.PrivKey) {
id, err := peer.IDFromPublicKey(privk.GetPublic())
if err != nil {
t.Fatal(err)
}
m := pb.Message{
Data: []byte("abc"),
TopicIDs: []string{"foo"},
From: []byte(id),
Seqno: []byte("123"),
}
signMessage(id, privk, &m)
err = verifyMessageSignature(&m)
if err != nil {
t.Fatal(err)
}
}