mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2024-12-26 23:30:27 +08:00
a182f52659
This implements #4 from #43. fixes #43
22 lines
491 B
Go
22 lines
491 B
Go
package test
|
|
|
|
import (
|
|
"math/rand"
|
|
"sync/atomic"
|
|
|
|
ci "github.com/libp2p/go-libp2p-core/crypto"
|
|
)
|
|
|
|
var globalSeed int64
|
|
|
|
func RandTestKeyPair(typ, bits int) (ci.PrivKey, ci.PubKey, error) {
|
|
// workaround for low time resolution
|
|
seed := atomic.AddInt64(&globalSeed, 1)
|
|
return SeededTestKeyPair(typ, bits, seed)
|
|
}
|
|
|
|
func SeededTestKeyPair(typ, bits int, seed int64) (ci.PrivKey, ci.PubKey, error) {
|
|
r := rand.New(rand.NewSource(seed))
|
|
return ci.GenerateKeyPairWithReader(typ, bits, r)
|
|
}
|