@@ -5,7 +5,8 @@ function run_test(algorithmNames, slowTest) {
55 setup ( { explicit_timeout : true } ) ;
66
77// 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.
910//
1011// There are a lot of combinations of possible parameters,
1112// resulting in a very large number of tests
@@ -68,9 +69,32 @@ function run_test(algorithmNames, slowTest) {
6869 } else {
6970 assert_goodCryptoKey ( result , algorithm , extractable , usages , "secret" ) ;
7071 }
72+ return result ;
7173 } , 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+ } )
7498 } , testTag + ": generateKey" + parameterString ( algorithm , extractable , usages ) ) ;
7599 }
76100
0 commit comments