mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-02-03 05:50:11 +08:00
27 lines
628 B
Go
27 lines
628 B
Go
|
package testutil
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
|
||
|
u "github.com/ipfs/go-ipfs-util"
|
||
|
ci "github.com/ipfs/go-libp2p-crypto"
|
||
|
peer "github.com/ipfs/go-libp2p-peer"
|
||
|
)
|
||
|
|
||
|
func RandPeerID() (peer.ID, error) {
|
||
|
buf := make([]byte, 16)
|
||
|
if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
h := u.Hash(buf)
|
||
|
return peer.ID(h), nil
|
||
|
}
|
||
|
|
||
|
func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) {
|
||
|
return ci.GenerateKeyPairWithReader(ci.RSA, bits, u.NewTimeSeededRand())
|
||
|
}
|
||
|
|
||
|
func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) {
|
||
|
return ci.GenerateKeyPairWithReader(ci.RSA, 512, u.NewSeededRand(seed))
|
||
|
}
|