@@ -229,10 +229,10 @@ Map<String, dynamic> _exportJwkRsaPrivateOrPublicKey(
229
229
});
230
230
}
231
231
232
- KeyPair <_EvpPKey , _EvpPKey > _generateRsaKeyPair (
232
+ Future < KeyPair <_EvpPKey , _EvpPKey > > _generateRsaKeyPair (
233
233
int modulusLength,
234
234
BigInt publicExponent,
235
- ) {
235
+ ) async {
236
236
// Sanity check for the modulusLength
237
237
if (modulusLength < 256 || modulusLength > 16384 ) {
238
238
throw UnsupportedError (
@@ -251,13 +251,14 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
251
251
throw UnsupportedError ('publicExponent is not supported, try 3 or 65537' );
252
252
}
253
253
254
- return _Scope .sync ((scope) {
254
+ return _Scope .async ((scope) async {
255
255
// Generate private RSA key
256
256
final privRSA = scope.createRSA ();
257
257
258
258
final e = scope.createBN ();
259
259
_checkOpIsOne (ssl.BN_set_word (e, publicExponent.toInt ()));
260
- _checkOpIsOne (ssl.RSA_generate_key_ex (
260
+
261
+ _checkOpIsOne (await _RSA_generate_key_ex (
261
262
privRSA,
262
263
modulusLength,
263
264
e,
@@ -284,3 +285,20 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
284
285
);
285
286
});
286
287
}
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