Skip to content

Commit

Permalink
fix PrivKey Marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
ta0li committed Jan 4, 2022
1 parent f257d37 commit 3a5b910
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 7 additions & 5 deletions app/node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ func Init(ctx context.Context, r repo.Repo, gen genesis.InitFunc, opts ...InitOp
return nil
}

func initPeerKey(store fskeystore.Keystore, key acrypto.PrivKey) error {
func initPeerKey(store fskeystore.Keystore, pk acrypto.PrivKey) error {
var err error
if key == nil {
key, _, err = acrypto.GenerateKeyPair(acrypto.RSA, defaultPeerKeyBits)
if pk == nil {
pk, _, err = acrypto.GenerateKeyPair(acrypto.RSA, defaultPeerKeyBits)
if err != nil {
return errors.Wrap(err, "failed to create peer key")
}
}
data, err := key.Raw() // TODO ?

kbytes, err := acrypto.MarshalPrivateKey(pk)
if err != nil {
return err
}
if err := store.Put("self", data); err != nil {

if err := store.Put("self", kbytes); err != nil {
return errors.Wrap(err, "failed to store private key")
}
return nil
Expand Down
7 changes: 5 additions & 2 deletions pkg/repo/fskeystore/fskeystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fskeystore
import (
"bytes"
"fmt"
crypto "github.com/libp2p/go-libp2p-crypto"
"io/ioutil"
"math/rand"
"os"
Expand Down Expand Up @@ -262,11 +263,13 @@ func privKeyOrFatal(t *testing.T) []byte {
if err != nil {
t.Fatal(err)
}
data, err := priv.Bytes()

kbytes, err := crypto.MarshalPrivateKey(priv)
if err != nil {
t.Fatal(err)
}
return data

return kbytes
}

func assertGetKey(ks Keystore, name string, exp []byte) error {
Expand Down

0 comments on commit 3a5b910

Please sign in to comment.