@@ -269,14 +269,12 @@ async function ecImportKey(
269
269
case 'NODE-X25519' :
270
270
// Fall through
271
271
case 'NODE-X448' :
272
- checkNamedCurve = false ;
273
272
if ( algorithm . name !== 'ECDH' )
274
273
throw lazyDOMException ( 'Invalid algorithm name.' , 'DataError' ) ;
275
274
break ;
276
275
case 'NODE-ED25519' :
277
276
// Fall through
278
277
case 'NODE-ED448' :
279
- checkNamedCurve = false ;
280
278
if ( algorithm . name !== namedCurve )
281
279
throw lazyDOMException ( 'Invalid algorithm name.' , 'DataError' ) ;
282
280
break ;
@@ -310,7 +308,6 @@ async function ecImportKey(
310
308
throw lazyDOMException ( 'Invalid JWK keyData' , 'DataError' ) ;
311
309
switch ( keyData . kty ) {
312
310
case 'OKP' : {
313
- checkNamedCurve = false ;
314
311
const isPublic = keyData . d === undefined ;
315
312
316
313
let type ;
@@ -395,7 +392,6 @@ async function ecImportKey(
395
392
case 'NODE-X25519' :
396
393
// Fall through
397
394
case 'NODE-X448' :
398
- checkNamedCurve = false ;
399
395
if ( algorithm . public !== undefined )
400
396
validateBoolean ( algorithm . public , 'algorithm.public' ) ;
401
397
if ( algorithm . name !== 'ECDH' )
@@ -409,7 +405,6 @@ async function ecImportKey(
409
405
case 'NODE-ED25519' :
410
406
// Fall through
411
407
case 'NODE-ED448' :
412
- checkNamedCurve = false ;
413
408
if ( algorithm . public !== undefined )
414
409
validateBoolean ( algorithm . public , 'algorithm.public' ) ;
415
410
if ( algorithm . name !== namedCurve )
@@ -436,30 +431,27 @@ async function ecImportKey(
436
431
throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
437
432
break ;
438
433
case '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' ) {
453
443
throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
454
444
}
455
445
break ;
456
446
case 'NODE-ED25519' :
457
447
if ( keyObject . asymmetricKeyType !== 'ed25519' )
458
448
throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
449
+ checkNamedCurve = false ;
459
450
break ;
460
451
case 'NODE-ED448' :
461
452
if ( keyObject . asymmetricKeyType !== 'ed448' )
462
453
throw lazyDOMException ( 'Invalid key type' , 'DataError' ) ;
454
+ checkNamedCurve = false ;
463
455
break ;
464
456
}
465
457
0 commit comments