43 lines
817 B
Go
43 lines
817 B
Go
package floodsub
|
|
|
|
import (
|
|
"testing"
|
|
|
|
pb "github.com/libp2p/go-floodsub/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)
|
|
}
|
|
}
|