2019-05-23 23:07:58 +08:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
ci "github.com/libp2p/go-libp2p-core/crypto"
|
|
|
|
)
|
|
|
|
|
2019-07-23 06:10:43 +08:00
|
|
|
var globalSeed int64
|
2019-05-23 23:07:58 +08:00
|
|
|
|
|
|
|
func RandTestKeyPair(typ, bits int) (ci.PrivKey, ci.PubKey, error) {
|
|
|
|
// workaround for low time resolution
|
2019-07-23 06:10:43 +08:00
|
|
|
seed := atomic.AddInt64(&globalSeed, 1)
|
|
|
|
return SeededTestKeyPair(typ, bits, seed)
|
2019-05-23 23:07:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func SeededTestKeyPair(typ, bits int, seed int64) (ci.PrivKey, ci.PubKey, error) {
|
|
|
|
r := rand.New(rand.NewSource(seed))
|
|
|
|
return ci.GenerateKeyPairWithReader(typ, bits, r)
|
|
|
|
}
|