2018-09-23 11:49:00 +00:00
|
|
|
package p2pd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
2019-05-26 22:58:53 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/crypto"
|
2018-09-23 11:49:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ReadIdentity(path string) (crypto.PrivKey, error) {
|
|
|
|
bytes, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return crypto.UnmarshalPrivateKey(bytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func WriteIdentity(k crypto.PrivKey, path string) error {
|
|
|
|
bytes, err := crypto.MarshalPrivateKey(k)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-23 12:05:11 +00:00
|
|
|
return ioutil.WriteFile(path, bytes, 0400)
|
2018-09-23 11:49:00 +00:00
|
|
|
}
|