mirror of
https://github.com/codex-storage/nim-websock.git
synced 2025-02-02 13:53:21 +00:00
Remove newRng (#132)
This commit is contained in:
parent
acbe30e9ca
commit
cf8b8ce235
@ -121,7 +121,7 @@ suite "Decode frame extensions flow":
|
||||
var
|
||||
address: TransportAddress
|
||||
server: StreamServer
|
||||
maskKey = genMaskKey(newRng())
|
||||
maskKey = genMaskKey(HmacDrbgContext.new())
|
||||
transport: StreamTransport
|
||||
reader: AsyncStreamReader
|
||||
frame: Frame
|
||||
|
@ -806,7 +806,7 @@ suite "Test Payload":
|
||||
address = initTAddress("127.0.0.1:8888"),
|
||||
frameSize = maxFrameSize)
|
||||
|
||||
let maskKey = genMaskKey(newRng())
|
||||
let maskKey = genMaskKey(HmacDrbgContext.new())
|
||||
await session.stream.writer.write(
|
||||
(await Frame(
|
||||
fin: false,
|
||||
@ -866,7 +866,7 @@ suite "Test Payload":
|
||||
pong = true
|
||||
)
|
||||
|
||||
let maskKey = genMaskKey(newRng())
|
||||
let maskKey = genMaskKey(HmacDrbgContext.new())
|
||||
await session.stream.writer.write(
|
||||
(await Frame(
|
||||
fin: false,
|
||||
|
@ -13,13 +13,7 @@ export rand
|
||||
## Random helpers: similar as in stdlib, but with HmacDrbgContext rng
|
||||
const randMax = 18_446_744_073_709_551_615'u64
|
||||
|
||||
type
|
||||
Rng* = ref HmacDrbgContext
|
||||
|
||||
proc newRng*(): Rng =
|
||||
# You should only create one instance of the RNG per application / library
|
||||
# Ref is used so that it can be shared between components
|
||||
HmacDrbgContext.new()
|
||||
type Rng* = ref HmacDrbgContext
|
||||
|
||||
proc rand*(rng: Rng, max: Natural): int =
|
||||
if max == 0: return 0
|
||||
|
@ -120,7 +120,7 @@ proc connect*(
|
||||
rng: Rng = nil): Future[WSSession] {.async.} =
|
||||
|
||||
let
|
||||
rng = if isNil(rng): newRng() else: rng
|
||||
rng = if isNil(rng): HmacDrbgContext.new() else: rng
|
||||
key = Base64Pad.encode(genWebSecKey(rng))
|
||||
hostname = if hostName.len > 0: hostName else: $host
|
||||
|
||||
@ -364,7 +364,7 @@ proc new*(
|
||||
return WSServer(
|
||||
protocols: @protos,
|
||||
masked: false,
|
||||
rng: if isNil(rng): newRng() else: rng,
|
||||
rng: if isNil(rng): HmacDrbgContext.new() else: rng,
|
||||
frameSize: frameSize,
|
||||
factories: @factories,
|
||||
onPing: onPing,
|
||||
|
Loading…
x
Reference in New Issue
Block a user