-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathwebcrypto-webidl.js
More file actions
113 lines (109 loc) Β· 3.77 KB
/
webcrypto-webidl.js
File metadata and controls
113 lines (109 loc) Β· 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
op: [
'normalizeAlgorithm-string',
'normalizeAlgorithm-dict',
'webidl-dict',
'webidl-algorithm-identifier-string',
'webidl-algorithm-identifier-object',
'webidl-dict-enforce-range',
'webidl-dict-ensure-sha',
'webidl-dict-null',
],
n: [1e6],
}, { flags: ['--expose-internals'] });
function main({ n, op }) {
const { normalizeAlgorithm } = require('internal/crypto/util');
switch (op) {
case 'normalizeAlgorithm-string': {
// String shortcut + null dictionary (cheapest path).
bench.start();
for (let i = 0; i < n; i++)
normalizeAlgorithm('SHA-256', 'digest');
bench.end(n);
break;
}
case 'normalizeAlgorithm-dict': {
// Object input with a dictionary type (no BufferSource members).
const alg = { name: 'ECDSA', hash: 'SHA-256' };
bench.start();
for (let i = 0; i < n; i++)
normalizeAlgorithm(alg, 'sign');
bench.end(n);
break;
}
case 'webidl-dict': {
// WebIDL dictionary converter in isolation.
const webidl = require('internal/crypto/webidl');
const input = { name: 'AES-GCM', iv: new Uint8Array(12) };
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.AeadParams(input, opts);
bench.end(n);
break;
}
case 'webidl-algorithm-identifier-string': {
// Exercises converters.AlgorithmIdentifier string path (isObjectType
// fast-reject + DOMString conversion).
const webidl = require('internal/crypto/webidl');
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.AlgorithmIdentifier('SHA-256', opts);
bench.end(n);
break;
}
case 'webidl-algorithm-identifier-object': {
// Exercises converters.AlgorithmIdentifier object path (isObjectType
// fast-accept, no dictionary walk).
const webidl = require('internal/crypto/webidl');
const input = { name: 'SHA-256' };
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.AlgorithmIdentifier(input, opts);
bench.end(n);
break;
}
case 'webidl-dict-enforce-range': {
// Exercises shared enforceRange integer wrappers (RsaKeyGenParams has
// both modulusLength: unsigned long and publicExponent: BigInteger).
const webidl = require('internal/crypto/webidl');
const input = {
name: 'RSASSA-PKCS1-v1_5',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
};
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.RsaKeyGenParams(input, opts);
bench.end(n);
break;
}
case 'webidl-dict-ensure-sha': {
// Exercises ensureSHA on a hash member (no lowercase allocation).
const webidl = require('internal/crypto/webidl');
const input = { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' };
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.RsaHashedImportParams(input, opts);
bench.end(n);
break;
}
case 'webidl-dict-null': {
// Exercises the null/undefined fast path in createDictionaryConverter
// (JsonWebKey has no required members).
const webidl = require('internal/crypto/webidl');
const opts = { prefix: 'test', context: 'test' };
bench.start();
for (let i = 0; i < n; i++)
webidl.converters.JsonWebKey(undefined, opts);
bench.end(n);
break;
}
}
}