MCPcopy Index your code
hub / github.com/nodejs/node / validateJwk

Function validateJwk

lib/internal/crypto/webcrypto_util.js:145–206  ·  view source on GitHub ↗
(keyData, kty, extractable, usagesSet, expectedUse)

Source from the content-addressed store, hash-verified

143}
144
145function validateJwk(keyData, kty, extractable, usagesSet, expectedUse) {
146 if (typeof keyData.kty !== 'string')
147 throw lazyDOMException('Invalid keyData', 'DataError');
148 if (keyData.kty !== kty)
149 throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
150 switch (kty) {
151 case 'RSA':
152 if (typeof keyData.n !== 'string' ||
153 typeof keyData.e !== 'string' ||
154 (keyData.d !== undefined && typeof keyData.d !== 'string'))
155 throw lazyDOMException('Invalid keyData', 'DataError');
156 if (typeof keyData.d === 'string' &&
157 (typeof keyData.p !== 'string' ||
158 typeof keyData.q !== 'string' ||
159 typeof keyData.dp !== 'string' ||
160 typeof keyData.dq !== 'string' ||
161 typeof keyData.qi !== 'string'))
162 throw lazyDOMException('Invalid keyData', 'DataError');
163 break;
164 case 'EC':
165 if (typeof keyData.crv !== 'string' ||
166 typeof keyData.x !== 'string' ||
167 typeof keyData.y !== 'string' ||
168 (keyData.d !== undefined && typeof keyData.d !== 'string'))
169 throw lazyDOMException('Invalid keyData', 'DataError');
170 break;
171 case 'OKP':
172 if (typeof keyData.crv !== 'string' ||
173 typeof keyData.x !== 'string' ||
174 (keyData.d !== undefined && typeof keyData.d !== 'string'))
175 throw lazyDOMException('Invalid keyData', 'DataError');
176 break;
177 case 'oct':
178 if (typeof keyData.k !== 'string')
179 throw lazyDOMException('Invalid keyData', 'DataError');
180 break;
181 case 'AKP':
182 if (typeof keyData.alg !== 'string' ||
183 typeof keyData.pub !== 'string' ||
184 (keyData.priv !== undefined && typeof keyData.priv !== 'string'))
185 throw lazyDOMException('Invalid keyData', 'DataError');
186 break;
187 /* c8 ignore start */
188 default: {
189 const assert = require('internal/assert');
190 assert.fail('Unreachable code');
191 }
192 /* c8 ignore stop */
193 }
194 if (usagesSet.size > 0 && keyData.use !== undefined) {
195 if (keyData.use !== expectedUse)
196 throw lazyDOMException('Invalid JWK "use" Parameter', 'DataError');
197 }
198 validateKeyOps(keyData.key_ops, usagesSet);
199 if (keyData.ext !== undefined &&
200 keyData.ext === false &&
201 extractable === true) {
202 throw lazyDOMException(

Callers 8

mlDsaImportKeyFunction · 0.85
mlKemImportKeyFunction · 0.85
c20pImportKeyFunction · 0.85
ecImportKeyFunction · 0.85
cfrgImportKeyFunction · 0.85
macImportKeyFunction · 0.85
aesImportKeyFunction · 0.85
rsaImportKeyFunction · 0.85

Calls 4

lazyDOMExceptionFunction · 0.85
validateKeyOpsFunction · 0.85
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…