Remove newRng (#132)

This commit is contained in:
Tanguy 2022-11-21 19:29:20 +01:00 committed by GitHub
parent acbe30e9ca
commit cf8b8ce235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 12 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,