Skip to content

Commit

Permalink
Update MultiplexingStreamFormatters.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
9at8 committed Oct 3, 2023
1 parent 289451d commit c73051d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/nerdbank-streams/src/MultiplexingStreamFormatters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OfferParameters } from './OfferParameters'
import { AcceptanceParameters } from './AcceptanceParameters'
import { MultiplexingStream } from './MultiplexingStream'
import * as nodejsCrypto from 'crypto'
import { getBufferFrom, writeAsync } from './Utilities'
import CancellationToken from 'cancellationtoken'
import * as msgpack from 'msgpack-lite'
Expand Down Expand Up @@ -42,15 +41,13 @@ export abstract class MultiplexingStreamFormatter {

protected static getIsOddRandomData(): Buffer {
const size = 16
const buffer = Buffer.alloc(size)

// browser crypto is available
if (globalThis && globalThis.crypto) {
const buffer = Buffer.from(new Uint8Array(size))
globalThis.crypto.getRandomValues(buffer)
return buffer
} else {
return nodejsCrypto.randomBytes(size)
for (let i = 0; i < size; i++) {
buffer[i] = Math.floor(Math.random() * 256)
}

return buffer
}

protected static isOdd(localRandom: Buffer, remoteRandom: Buffer): boolean {
Expand Down

0 comments on commit c73051d

Please sign in to comment.