@@ -269,14 +269,12 @@ async function ecImportKey(
269269case 'NODE-X25519' :
270270// Fall through
271271case 'NODE-X448' :
272- checkNamedCurve = false ;
273272if ( algorithm . name !== 'ECDH' )
274273throw lazyDOMException ( 'Invalid algorithm name.' , 'DataError' ) ;
275274break ;
276275case 'NODE-ED25519' :
277276// Fall through
278277case 'NODE-ED448' :
279- checkNamedCurve = false ;
280278if ( algorithm . name !== namedCurve )
281279throw lazyDOMException ( 'Invalid algorithm name.' , 'DataError' ) ;
282280break ;
@@ -310,7 +308,6 @@ async function ecImportKey(
310308throw lazyDOMException ( 'Invalid JWK keyData' , 'DataError' ) ;
311309switch ( keyData . kty ) {
312310case 'OKP' : {
313- checkNamedCurve = false ;
314311const isPublic = keyData . d === undefined ;
315312
316313let type ;
@@ -395,7 +392,6 @@ async function ecImportKey(
395392case 'NODE-X25519' :
396393// Fall through
397394case 'NODE-X448' :
398- checkNamedCurve = false ;
399395if ( algorithm . public !== undefined )
400396validateBoolean ( algorithm . public , 'algorithm.public' ) ;
401397if ( algorithm . name !== 'ECDH' )
@@ -409,7 +405,6 @@ async function ecImportKey(
409405case 'NODE-ED25519' :
410406// Fall through
411407case 'NODE-ED448' :
412- checkNamedCurve = false ;
413408if ( algorithm . public !== undefined )
414409validateBoolean ( algorithm . public , 'algorithm.public' ) ;
415410if ( algorithm . name !== namedCurve )
@@ -436,30 +431,27 @@ async function ecImportKey(
436431throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
437432break ;
438433case 'ECDH' :
439- if (
440- algorithm . namedCurve === 'NODE-X25519' &&
441- keyObject . asymmetricKeyType !== 'x25519'
442- ) {
443- throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
444- } else if (
445- algorithm . namedCurve === 'NODE-X448' &&
446- keyObject . asymmetricKeyType !== 'x448'
447- ) {
448- throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
449- } else if (
450- algorithm . namedCurve . startsWith ( 'P' ) &&
451- keyObject . asymmetricKeyType !== 'ec'
452- ) {
434+ if ( algorithm . namedCurve === 'NODE-X25519' ) {
435+ if ( keyObject . asymmetricKeyType !== 'x25519' )
436+ throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
437+ checkNamedCurve = false ;
438+ } else if ( algorithm . namedCurve === 'NODE-X448' ) {
439+ if ( keyObject . asymmetricKeyType !== 'x448' )
440+ throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
441+ checkNamedCurve = false ;
442+ } else if ( keyObject . asymmetricKeyType !== 'ec' ) {
453443throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
454444}
455445break ;
456446case 'NODE-ED25519' :
457447if ( keyObject . asymmetricKeyType !== 'ed25519' )
458448throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
449+ checkNamedCurve = false ;
459450break ;
460451case 'NODE-ED448' :
461452if ( keyObject . asymmetricKeyType !== 'ed448' )
462453throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
454+ checkNamedCurve = false ;
463455break ;
464456}
465457
0 commit comments