@@ -18,13 +18,6 @@ const {
1818} = internalBinding ( 'crypto' ) ;
1919
2020const {
21- codes : {
22- ERR_MISSING_OPTION ,
23- }
24- } = require ( 'internal/errors' ) ;
25-
26- const {
27- getArrayBufferOrView,
2821 getUsagesUnion,
2922 hasAnyNotIn,
3023 jobPromise,
@@ -76,7 +69,6 @@ function verifyAcceptableEcKeyUse(name, isPublic, usages) {
7669
7770function createECPublicKeyRaw ( namedCurve , keyData ) {
7871 const handle = new KeyObjectHandle ( ) ;
79- keyData = getArrayBufferOrView ( keyData , 'keyData' ) ;
8072
8173 if ( ! handle . initECRaw ( kNamedCurveAliases [ namedCurve ] , keyData ) ) {
8274 throw lazyDOMException ( 'Invalid keyData' , 'DataError' ) ;
@@ -204,50 +196,53 @@ async function ecImportKey(
204196 break ;
205197 }
206198 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' ) ;
209201 if ( keyData . kty !== 'EC' )
210- throw lazyDOMException ( 'Invalid key type ' , 'DataError' ) ;
202+ throw lazyDOMException ( 'Invalid JWK "kty" Parameter ' , 'DataError' ) ;
211203 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' ) ;
213207
214208 verifyAcceptableEcKeyUse (
215209 name ,
216210 keyData . d === undefined ,
217211 usagesSet ) ;
218212
219213 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' ) ;
224217 }
225218
226219 validateKeyOps ( keyData . key_ops , usagesSet ) ;
227220
228221 if ( keyData . ext !== undefined &&
229222 keyData . ext === false &&
230223 extractable === true ) {
231- throw lazyDOMException ( 'JWK is not extractable' , 'DataError' ) ;
224+ throw lazyDOMException (
225+ 'JWK "ext" Parameter and extractable mismatch' ,
226+ 'DataError' ) ;
232227 }
233228
234229 if ( algorithm . name === 'ECDSA' && keyData . alg !== undefined ) {
235- if ( typeof keyData . alg !== 'string' )
236- throw lazyDOMException ( 'Invalid alg' , 'DataError' ) ;
237230 let algNamedCurve ;
238231 switch ( keyData . alg ) {
239232 case 'ES256' : algNamedCurve = 'P-256' ; break ;
240233 case 'ES384' : algNamedCurve = 'P-384' ; break ;
241234 case 'ES512' : algNamedCurve = 'P-521' ; break ;
242235 }
243236 if ( algNamedCurve !== namedCurve )
244- throw lazyDOMException ( 'Named curve mismatch' , 'DataError' ) ;
237+ throw lazyDOMException (
238+ 'JWK "alg" does not match the requested algorithm' ,
239+ 'DataError' ) ;
245240 }
246241
247242 const handle = new KeyObjectHandle ( ) ;
248243 const type = handle . initJwk ( keyData , namedCurve ) ;
249244 if ( type === undefined )
250- throw lazyDOMException ( 'Invalid JWK keyData ' , 'DataError' ) ;
245+ throw lazyDOMException ( 'Invalid JWK' , 'DataError' ) ;
251246 keyObject = type === kKeyTypePrivate ?
252247 new PrivateKeyObject ( handle ) :
253248 new PublicKeyObject ( handle ) ;
@@ -289,8 +284,6 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) {
289284 if ( key . type !== type )
290285 throw lazyDOMException ( `Key must be a ${ type } key` , 'InvalidAccessError' ) ;
291286
292- if ( hash === undefined )
293- throw new ERR_MISSING_OPTION ( 'algorithm.hash' ) ;
294287 const hashname = normalizeHashName ( hash . name ) ;
295288
296289 return jobPromise ( ( ) => new SignJob (
0 commit comments