File tree 5 files changed +2
-45
lines changed
5 files changed +2
-45
lines changed Original file line number Diff line number Diff line change @@ -43,12 +43,6 @@ export interface Platform {
43
43
/** Converts a binary string to a Base64 encoded string. */
44
44
btoa ( raw : string ) : string ;
45
45
46
- /**
47
- * Generates `nBytes` of random bytes. If `nBytes` is negative, an empty array
48
- * will be returned.
49
- */
50
- randomBytes ( nBytes : number ) : Uint8Array ;
51
-
52
46
/** The Platform's 'window' implementation or null if not available. */
53
47
readonly window : Window | null ;
54
48
Original file line number Diff line number Diff line change @@ -25,10 +25,6 @@ import { NoopConnectivityMonitor } from '../remote/connectivity_monitor_noop';
25
25
import { BrowserConnectivityMonitor } from './browser_connectivity_monitor' ;
26
26
import { WebChannelConnection } from './webchannel_connection' ;
27
27
28
- // Polyfill for IE
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- const crypto = window . crypto || ( window as any ) . msCrypto ;
31
-
32
28
export class BrowserPlatform implements Platform {
33
29
readonly useProto3Json = true ;
34
30
readonly base64Available : boolean ;
@@ -72,14 +68,4 @@ export class BrowserPlatform implements Platform {
72
68
btoa ( raw : string ) : string {
73
69
return btoa ( raw ) ;
74
70
}
75
-
76
- randomBytes ( nBytes : number ) : Uint8Array {
77
- if ( nBytes <= 0 ) {
78
- return new Uint8Array ( ) ;
79
- }
80
-
81
- const v = new Uint8Array ( nBytes ) ;
82
- crypto . getRandomValues ( v ) ;
83
- return v ;
84
- }
85
71
}
Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- import { randomBytes } from 'crypto' ;
19
18
import { inspect } from 'util' ;
20
19
21
20
import { DatabaseId , DatabaseInfo } from '../core/database_info' ;
@@ -76,12 +75,4 @@ export class NodePlatform implements Platform {
76
75
btoa ( raw : string ) : string {
77
76
return new Buffer ( raw , 'binary' ) . toString ( 'base64' ) ;
78
77
}
79
-
80
- randomBytes ( nBytes : number ) : Uint8Array {
81
- if ( nBytes <= 0 ) {
82
- return new Uint8Array ( ) ;
83
- }
84
-
85
- return randomBytes ( nBytes ) ;
86
- }
87
78
}
Original file line number Diff line number Diff line change 16
16
*/
17
17
18
18
import { assert } from './assert' ;
19
- import { PlatformSupport } from '../platform/platform' ;
20
19
21
20
export type EventHandler < E > = ( value : E ) => void ;
22
21
export interface Indexable {
@@ -29,17 +28,8 @@ export class AutoId {
29
28
const chars =
30
29
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
31
30
let autoId = '' ;
32
- while ( autoId . length < 20 ) {
33
- const bytes = PlatformSupport . getPlatform ( ) . randomBytes ( 40 ) ;
34
- for ( const b of Array . from ( bytes ) ) {
35
- // Length of `chars` is 62. We only take bytes between 0 and 62*4-1
36
- // (both inclusive). The value is then evenly mapped to indices of `char`
37
- // via a modulo operation.
38
- const maxValue = 62 * 4 - 1 ;
39
- if ( autoId . length < 20 && b <= maxValue ) {
40
- autoId += chars . charAt ( b % 62 ) ;
41
- }
42
- }
31
+ for ( let i = 0 ; i < 20 ; i ++ ) {
32
+ autoId += chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ;
43
33
}
44
34
assert ( autoId . length === 20 , 'Invalid auto ID: ' + autoId ) ;
45
35
return autoId ;
Original file line number Diff line number Diff line change @@ -266,10 +266,6 @@ export class TestPlatform implements Platform {
266
266
btoa ( raw : string ) : string {
267
267
return this . basePlatform . btoa ( raw ) ;
268
268
}
269
-
270
- randomBytes ( nBytes : number ) : Uint8Array {
271
- return this . basePlatform . randomBytes ( nBytes ) ;
272
- }
273
269
}
274
270
275
271
/** Returns true if we are running under Node. */
You can’t perform that action at this time.
0 commit comments