@@ -18,13 +18,6 @@ const {
18
18
} = internalBinding ( 'crypto' ) ;
19
19
20
20
const {
21
- codes : {
22
- ERR_MISSING_OPTION ,
23
- }
24
- } = require ( 'internal/errors' ) ;
25
-
26
- const {
27
- getArrayBufferOrView,
28
21
getUsagesUnion,
29
22
hasAnyNotIn,
30
23
jobPromise,
@@ -76,7 +69,6 @@ function verifyAcceptableEcKeyUse(name, isPublic, usages) {
76
69
77
70
function createECPublicKeyRaw ( namedCurve , keyData ) {
78
71
const handle = new KeyObjectHandle ( ) ;
79
- keyData = getArrayBufferOrView ( keyData , 'keyData' ) ;
80
72
81
73
if ( ! handle . initECRaw ( kNamedCurveAliases [ namedCurve ] , keyData ) ) {
82
74
throw lazyDOMException ( 'Invalid keyData' , 'DataError' ) ;
@@ -204,50 +196,53 @@ async function ecImportKey(
204
196
break ;
205
197
}
206
198
case 'jwk' : {
207
- if ( keyData == null || typeof keyData !== 'object' )
208
- throw lazyDOMException ( 'Invalid JWK keyData' , 'DataError' ) ;
199
+ if ( ! keyData . kty )
200
+ throw lazyDOMException ( 'Invalid keyData' , 'DataError' ) ;
209
201
if ( keyData . kty !== 'EC' )
210
- throw lazyDOMException ( 'Invalid key type ' , 'DataError' ) ;
202
+ throw lazyDOMException ( 'Invalid JWK "kty" Parameter ' , 'DataError' ) ;
211
203
if ( keyData . crv !== namedCurve )
212
- throw lazyDOMException ( 'Named curve mismatch' , 'DataError' ) ;
204
+ throw lazyDOMException (
205
+ 'JWK "crv" does not match the requested algorithm' ,
206
+ 'DataError' ) ;
213
207
214
208
verifyAcceptableEcKeyUse (
215
209
name ,
216
210
keyData . d === undefined ,
217
211
usagesSet ) ;
218
212
219
213
if ( usagesSet . size > 0 && keyData . use !== undefined ) {
220
- if ( algorithm . name === 'ECDSA' && keyData . use !== 'sig' )
221
- throw lazyDOMException ( 'Invalid use type' , 'DataError' ) ;
222
- if ( algorithm . name === 'ECDH' && keyData . use !== 'enc' )
223
- throw lazyDOMException ( 'Invalid use type' , 'DataError' ) ;
214
+ const checkUse = name === 'ECDH' ? 'enc' : 'sig' ;
215
+ if ( keyData . use !== checkUse )
216
+ throw lazyDOMException ( 'Invalid JWK "use" Parameter' , 'DataError' ) ;
224
217
}
225
218
226
219
validateKeyOps ( keyData . key_ops , usagesSet ) ;
227
220
228
221
if ( keyData . ext !== undefined &&
229
222
keyData . ext === false &&
230
223
extractable === true ) {
231
- throw lazyDOMException ( 'JWK is not extractable' , 'DataError' ) ;
224
+ throw lazyDOMException (
225
+ 'JWK "ext" Parameter and extractable mismatch' ,
226
+ 'DataError' ) ;
232
227
}
233
228
234
229
if ( algorithm . name === 'ECDSA' && keyData . alg !== undefined ) {
235
- if ( typeof keyData . alg !== 'string' )
236
- throw lazyDOMException ( 'Invalid alg' , 'DataError' ) ;
237
230
let algNamedCurve ;
238
231
switch ( keyData . alg ) {
239
232
case 'ES256' : algNamedCurve = 'P-256' ; break ;
240
233
case 'ES384' : algNamedCurve = 'P-384' ; break ;
241
234
case 'ES512' : algNamedCurve = 'P-521' ; break ;
242
235
}
243
236
if ( algNamedCurve !== namedCurve )
244
- throw lazyDOMException ( 'Named curve mismatch' , 'DataError' ) ;
237
+ throw lazyDOMException (
238
+ 'JWK "alg" does not match the requested algorithm' ,
239
+ 'DataError' ) ;
245
240
}
246
241
247
242
const handle = new KeyObjectHandle ( ) ;
248
243
const type = handle . initJwk ( keyData , namedCurve ) ;
249
244
if ( type === undefined )
250
- throw lazyDOMException ( 'Invalid JWK keyData ' , 'DataError' ) ;
245
+ throw lazyDOMException ( 'Invalid JWK' , 'DataError' ) ;
251
246
keyObject = type === kKeyTypePrivate ?
252
247
new PrivateKeyObject ( handle ) :
253
248
new PublicKeyObject ( handle ) ;
@@ -289,8 +284,6 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) {
289
284
if ( key . type !== type )
290
285
throw lazyDOMException ( `Key must be a ${ type } key` , 'InvalidAccessError' ) ;
291
286
292
- if ( hash === undefined )
293
- throw new ERR_MISSING_OPTION ( 'algorithm.hash' ) ;
294
287
const hashname = normalizeHashName ( hash . name ) ;
295
288
296
289
return jobPromise ( ( ) => new SignJob (
0 commit comments