@@ -920,12 +920,12 @@ async function wrapKey(format, key, wrappingKey, algorithm) {
920920 algorithm = normalizeAlgorithm ( algorithm , 'encrypt' ) ;
921921 }
922922
923- if ( algorithm . name !== wrappingKey [ kAlgorithm ] . name ||
924- ! ArrayPrototypeIncludes ( wrappingKey [ kKeyUsages ] , 'wrapKey' ) ) {
923+ if ( algorithm . name !== wrappingKey [ kAlgorithm ] . name )
924+ throw lazyDOMException ( 'Key algorithm mismatch' , 'InvalidAccessError' ) ;
925+
926+ if ( ! ArrayPrototypeIncludes ( wrappingKey [ kKeyUsages ] , 'wrapKey' ) )
925927 throw lazyDOMException (
926- 'The requested operation is not valid for the provided key' ,
927- 'InvalidAccessError' ) ;
928- }
928+ 'Unable to use this key to wrapKey' , 'InvalidAccessError' ) ;
929929
930930 let keyData = await FunctionPrototypeCall ( exportKey , this , format , key ) ;
931931
@@ -1005,12 +1005,12 @@ async function unwrapKey(
10051005
10061006 unwrappedKeyAlgo = normalizeAlgorithm ( unwrappedKeyAlgo , 'importKey' ) ;
10071007
1008- if ( unwrapAlgo . name !== unwrappingKey [ kAlgorithm ] . name ||
1009- ! ArrayPrototypeIncludes ( unwrappingKey [ kKeyUsages ] , 'unwrapKey' ) ) {
1008+ if ( unwrapAlgo . name !== unwrappingKey [ kAlgorithm ] . name )
1009+ throw lazyDOMException ( 'Key algorithm mismatch' , 'InvalidAccessError' ) ;
1010+
1011+ if ( ! ArrayPrototypeIncludes ( unwrappingKey [ kKeyUsages ] , 'unwrapKey' ) )
10101012 throw lazyDOMException (
1011- 'The requested operation is not valid for the provided key' ,
1012- 'InvalidAccessError' ) ;
1013- }
1013+ 'Unable to use this key to unwrapKey' , 'InvalidAccessError' ) ;
10141014
10151015 let keyData = await cipherOrWrap (
10161016 kWebCryptoCipherDecrypt ,
@@ -1186,12 +1186,12 @@ async function encrypt(algorithm, key, data) {
11861186
11871187 algorithm = normalizeAlgorithm ( algorithm , 'encrypt' ) ;
11881188
1189- if ( algorithm . name !== key [ kAlgorithm ] . name ||
1190- ! ArrayPrototypeIncludes ( key [ kKeyUsages ] , 'encrypt' ) ) {
1189+ if ( algorithm . name !== key [ kAlgorithm ] . name )
1190+ throw lazyDOMException ( 'Key algorithm mismatch' , 'InvalidAccessError' ) ;
1191+
1192+ if ( ! ArrayPrototypeIncludes ( key [ kKeyUsages ] , 'encrypt' ) )
11911193 throw lazyDOMException (
1192- 'The requested operation is not valid for the provided key' ,
1193- 'InvalidAccessError' ) ;
1194- }
1194+ 'Unable to use this key to encrypt' , 'InvalidAccessError' ) ;
11951195
11961196 return await cipherOrWrap (
11971197 kWebCryptoCipherEncrypt ,
@@ -1223,12 +1223,12 @@ async function decrypt(algorithm, key, data) {
12231223
12241224 algorithm = normalizeAlgorithm ( algorithm , 'decrypt' ) ;
12251225
1226- if ( algorithm . name !== key [ kAlgorithm ] . name ||
1227- ! ArrayPrototypeIncludes ( key [ kKeyUsages ] , 'decrypt' ) ) {
1226+ if ( algorithm . name !== key [ kAlgorithm ] . name )
1227+ throw lazyDOMException ( 'Key algorithm mismatch' , 'InvalidAccessError' ) ;
1228+
1229+ if ( ! ArrayPrototypeIncludes ( key [ kKeyUsages ] , 'decrypt' ) )
12281230 throw lazyDOMException (
1229- 'The requested operation is not valid for the provided key' ,
1230- 'InvalidAccessError' ) ;
1231- }
1231+ 'Unable to use this key to decrypt' , 'InvalidAccessError' ) ;
12321232
12331233 return await cipherOrWrap (
12341234 kWebCryptoCipherDecrypt ,
0 commit comments