@@ -378,7 +378,7 @@ async function deriveKey(
378
378
}
379
379
380
380
return ReflectApply (
381
- importKey ,
381
+ importKeySync ,
382
382
this ,
383
383
[ 'raw-secret' , bits , derivedKeyAlgorithm , extractable , keyUsages ] ,
384
384
) ;
@@ -734,40 +734,7 @@ function aliasKeyFormat(format) {
734
734
}
735
735
}
736
736
737
- async function importKey (
738
- format ,
739
- keyData ,
740
- algorithm ,
741
- extractable ,
742
- keyUsages ) {
743
- if ( this !== subtle ) throw new ERR_INVALID_THIS ( 'SubtleCrypto' ) ;
744
-
745
- webidl ??= require ( 'internal/crypto/webidl' ) ;
746
- const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'" ;
747
- webidl . requiredArguments ( arguments . length , 4 , { prefix } ) ;
748
- format = webidl . converters . KeyFormat ( format , {
749
- prefix,
750
- context : '1st argument' ,
751
- } ) ;
752
- const type = format === 'jwk' ? 'JsonWebKey' : 'BufferSource' ;
753
- keyData = webidl . converters [ type ] ( keyData , {
754
- prefix,
755
- context : '2nd argument' ,
756
- } ) ;
757
- algorithm = webidl . converters . AlgorithmIdentifier ( algorithm , {
758
- prefix,
759
- context : '3rd argument' ,
760
- } ) ;
761
- extractable = webidl . converters . boolean ( extractable , {
762
- prefix,
763
- context : '4th argument' ,
764
- } ) ;
765
- keyUsages = webidl . converters [ 'sequence<KeyUsage>' ] ( keyUsages , {
766
- prefix,
767
- context : '5th argument' ,
768
- } ) ;
769
-
770
- algorithm = normalizeAlgorithm ( algorithm , 'importKey' ) ;
737
+ function importKeySync ( format , keyData , algorithm , extractable , keyUsages ) {
771
738
let result ;
772
739
switch ( algorithm . name ) {
773
740
case 'RSASSA-PKCS1-v1_5' :
@@ -879,6 +846,48 @@ async function importKey(
879
846
return result ;
880
847
}
881
848
849
+ async function importKey (
850
+ format ,
851
+ keyData ,
852
+ algorithm ,
853
+ extractable ,
854
+ keyUsages ) {
855
+ if ( this !== subtle ) throw new ERR_INVALID_THIS ( 'SubtleCrypto' ) ;
856
+
857
+ webidl ??= require ( 'internal/crypto/webidl' ) ;
858
+ const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'" ;
859
+ webidl . requiredArguments ( arguments . length , 4 , { prefix } ) ;
860
+ format = webidl . converters . KeyFormat ( format , {
861
+ prefix,
862
+ context : '1st argument' ,
863
+ } ) ;
864
+ const type = format === 'jwk' ? 'JsonWebKey' : 'BufferSource' ;
865
+ keyData = webidl . converters [ type ] ( keyData , {
866
+ prefix,
867
+ context : '2nd argument' ,
868
+ } ) ;
869
+ algorithm = webidl . converters . AlgorithmIdentifier ( algorithm , {
870
+ prefix,
871
+ context : '3rd argument' ,
872
+ } ) ;
873
+ extractable = webidl . converters . boolean ( extractable , {
874
+ prefix,
875
+ context : '4th argument' ,
876
+ } ) ;
877
+ keyUsages = webidl . converters [ 'sequence<KeyUsage>' ] ( keyUsages , {
878
+ prefix,
879
+ context : '5th argument' ,
880
+ } ) ;
881
+
882
+ algorithm = normalizeAlgorithm ( algorithm , 'importKey' ) ;
883
+
884
+ return ReflectApply (
885
+ importKeySync ,
886
+ this ,
887
+ [ format , keyData , algorithm , extractable , keyUsages ] ,
888
+ ) ;
889
+ }
890
+
882
891
// subtle.wrapKey() is essentially a subtle.exportKey() followed
883
892
// by a subtle.encrypt().
884
893
async function wrapKey ( format , key , wrappingKey , algorithm ) {
@@ -985,6 +994,8 @@ async function unwrapKey(
985
994
unwrapAlgo = normalizeAlgorithm ( unwrapAlgo , 'decrypt' ) ;
986
995
}
987
996
997
+ unwrappedKeyAlgo = normalizeAlgorithm ( unwrappedKeyAlgo , 'importKey' ) ;
998
+
988
999
let keyData = await cipherOrWrap (
989
1000
kWebCryptoCipherDecrypt ,
990
1001
unwrapAlgo ,
@@ -1005,7 +1016,7 @@ async function unwrapKey(
1005
1016
}
1006
1017
1007
1018
return ReflectApply (
1008
- importKey ,
1019
+ importKeySync ,
1009
1020
this ,
1010
1021
[ format , keyData , unwrappedKeyAlgo , extractable , keyUsages ] ,
1011
1022
) ;
@@ -1318,8 +1329,8 @@ async function encapsulateKey(encapsulationAlgorithm, encapsulationKey, sharedKe
1318
1329
throw lazyDOMException ( 'Unrecognized algorithm name' , 'NotSupportedError' ) ;
1319
1330
}
1320
1331
1321
- const sharedKey = await ReflectApply (
1322
- importKey ,
1332
+ const sharedKey = ReflectApply (
1333
+ importKeySync ,
1323
1334
this ,
1324
1335
[ 'raw-secret' , encapsulateBits . sharedKey , normalizedSharedKeyAlgorithm , extractable , usages ] ,
1325
1336
) ;
@@ -1439,7 +1450,7 @@ async function decapsulateKey(
1439
1450
}
1440
1451
1441
1452
return ReflectApply (
1442
- importKey ,
1453
+ importKeySync ,
1443
1454
this ,
1444
1455
[ 'raw-secret' , decapsulatedBits , normalizedSharedKeyAlgorithm , extractable , usages ] ,
1445
1456
) ;
0 commit comments