Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions tests/tools/crypto.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@
import chronos/streams/tlsstream, stew/byteutils
import ../../libp2p/[crypto/crypto, transports/tls/certificate]

type RngWrap = object
rng: ref HmacDrbgContext

var rngVar: RngWrap
var rngSingleton {.threadvar.}: ref HmacDrbgContext
rngSingleton = newRng()

proc getRng(): ref HmacDrbgContext =
# TODO if `rngVar` is a threadvar like it should be, there are random and
# spurious compile failures on mac - this is not gcsafe but for the
# purpose of the tests, it's ok as long as we only use a single thread
{.gcsafe.}:
if rngVar.rng.isNil:
rngVar.rng = newRng()
rngVar.rng
rngSingleton

template rng*(): ref HmacDrbgContext =
getRng()
Expand Down
Loading