@@ -229,10 +229,10 @@ Map<String, dynamic> _exportJwkRsaPrivateOrPublicKey(
229229 });
230230}
231231
232- KeyPair <_EvpPKey , _EvpPKey > _generateRsaKeyPair (
232+ Future < KeyPair <_EvpPKey , _EvpPKey > > _generateRsaKeyPair (
233233 int modulusLength,
234234 BigInt publicExponent,
235- ) {
235+ ) async {
236236 // Sanity check for the modulusLength
237237 if (modulusLength < 256 || modulusLength > 16384 ) {
238238 throw UnsupportedError (
@@ -251,13 +251,14 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
251251 throw UnsupportedError ('publicExponent is not supported, try 3 or 65537' );
252252 }
253253
254- return _Scope .sync ((scope) {
254+ return _Scope .async ((scope) async {
255255 // Generate private RSA key
256256 final privRSA = scope.createRSA ();
257257
258258 final e = scope.createBN ();
259259 _checkOpIsOne (ssl.BN_set_word (e, publicExponent.toInt ()));
260- _checkOpIsOne (ssl.RSA_generate_key_ex (
260+
261+ _checkOpIsOne (await _RSA_generate_key_ex (
261262 privRSA,
262263 modulusLength,
263264 e,
@@ -284,3 +285,20 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
284285 );
285286 });
286287}
288+
289+ /// Helper function to run `ssl.RSA_generate_key_ex` in an [Isolate]
290+ /// using [Isolate.run] .
291+ ///
292+ /// Using this auxiliary function to wrap the call should reduce the risk that
293+ /// unnecessary variables are copied into the closure passed to [Isolate.run] .
294+ // ignore: non_constant_identifier_names
295+ Future <int > _RSA_generate_key_ex (
296+ ffi.Pointer <RSA > rsa,
297+ int bits,
298+ ffi.Pointer <BIGNUM > e,
299+ ffi.Pointer <BN_GENCB > cb,
300+ ) async =>
301+ await Isolate .run (
302+ () => ssl.RSA_generate_key_ex (rsa, bits, e, cb),
303+ debugName: 'RSA_generate_key_ex' ,
304+ );
0 commit comments