@@ -5,7 +5,8 @@ function run_test(algorithmNames, slowTest) {
5
5
setup ( { explicit_timeout : true } ) ;
6
6
7
7
// These tests check that generateKey successfully creates keys
8
- // when provided any of a wide set of correct parameters.
8
+ // when provided any of a wide set of correct parameters
9
+ // and that they can be exported afterwards.
9
10
//
10
11
// There are a lot of combinations of possible parameters,
11
12
// resulting in a very large number of tests
@@ -68,9 +69,32 @@ function run_test(algorithmNames, slowTest) {
68
69
} else {
69
70
assert_goodCryptoKey ( result , algorithm , extractable , usages , "secret" ) ;
70
71
}
72
+ return result ;
71
73
} , function ( err ) {
72
- assert_unreached ( "Threw an unexpected error: " + err . toString ( ) ) ;
73
- } ) ;
74
+ assert_unreached ( "generateKey threw an unexpected error: " + err . toString ( ) ) ;
75
+ } )
76
+ . then ( async function ( result ) {
77
+ if ( resultType === "CryptoKeyPair" ) {
78
+ await Promise . all ( [
79
+ subtle . exportKey ( 'jwk' , result . publicKey ) ,
80
+ subtle . exportKey ( 'spki' , result . publicKey ) ,
81
+ result . publicKey . algorithm . name . startsWith ( 'RSA' ) ? undefined : subtle . exportKey ( 'raw' , result . publicKey ) ,
82
+ ...( extractable ? [
83
+ subtle . exportKey ( 'jwk' , result . privateKey ) ,
84
+ subtle . exportKey ( 'pkcs8' , result . privateKey ) ,
85
+ ] : [ ] )
86
+ ] ) ;
87
+ } else {
88
+ if ( extractable ) {
89
+ await Promise . all ( [
90
+ subtle . exportKey ( 'raw' , result ) ,
91
+ subtle . exportKey ( 'jwk' , result ) ,
92
+ ] ) ;
93
+ }
94
+ }
95
+ } , function ( err ) {
96
+ assert_unreached ( "exportKey threw an unexpected error: " + err . toString ( ) ) ;
97
+ } )
74
98
} , testTag + ": generateKey" + parameterString ( algorithm , extractable , usages ) ) ;
75
99
}
76
100
0 commit comments