@@ -64,15 +64,15 @@ String _ecCurveToJwkCrv(EllipticCurve curve) {
64
64
65
65
/// Perform some post-import validation for EC keys.
66
66
void _validateEllipticCurveKey (
67
- ffi. Pointer < EVP_PKEY > key,
67
+ _EvpPKey key,
68
68
EllipticCurve curve,
69
69
) {
70
70
final scope = _Scope ();
71
71
try {
72
- _checkData (ssl.EVP_PKEY_id (key) == EVP_PKEY_EC ,
72
+ _checkData (ssl.EVP_PKEY_id . invoke (key) == EVP_PKEY_EC ,
73
73
message: 'key is not an EC key' );
74
74
75
- final ec = ssl.EVP_PKEY_get1_EC_KEY (key);
75
+ final ec = ssl.EVP_PKEY_get1_EC_KEY . invoke (key);
76
76
_checkData (ec.address != 0 , fallback: 'key is not an EC key' );
77
77
scope.defer (() => ssl.EC_KEY_free (ec));
78
78
@@ -93,35 +93,35 @@ void _validateEllipticCurveKey(
93
93
}
94
94
}
95
95
96
- ffi. Pointer < EVP_PKEY > _importPkcs8EcPrivateKey (
96
+ _EvpPKey _importPkcs8EcPrivateKey (
97
97
List <int > keyData,
98
98
EllipticCurve curve,
99
99
) {
100
- final key = _withDataAsCBS (keyData, ssl.EVP_parse_private_key );
101
- _checkData (key .address != 0 , fallback: 'unable to parse key' );
102
- _attachFinalizerEVP_PKEY ( key);
100
+ final k = _withDataAsCBS (keyData, ssl.EVP_parse_private_key );
101
+ _checkData (k .address != 0 , fallback: 'unable to parse key' );
102
+ final key = _EvpPKey . wrap (k );
103
103
104
104
_validateEllipticCurveKey (key, curve);
105
105
return key;
106
106
}
107
107
108
- ffi. Pointer < EVP_PKEY > _importSpkiEcPublicKey (
108
+ _EvpPKey _importSpkiEcPublicKey (
109
109
List <int > keyData,
110
110
EllipticCurve curve,
111
111
) {
112
112
// TODO: When calling EVP_parse_public_key it might wise to check that CBS_len(cbs) == 0 is true afterwards
113
113
// otherwise it might be that all of the contents of the key was not consumed and we should throw
114
114
// a FormatException. Notice that this the case for private/public keys, and RSA keys.
115
- final key = _withDataAsCBS (keyData, ssl.EVP_parse_public_key );
116
- _checkData (key .address != 0 , fallback: 'unable to parse key' );
117
- _attachFinalizerEVP_PKEY ( key);
115
+ final k = _withDataAsCBS (keyData, ssl.EVP_parse_public_key );
116
+ _checkData (k .address != 0 , fallback: 'unable to parse key' );
117
+ final key = _EvpPKey . wrap (k );
118
118
119
119
_validateEllipticCurveKey (key, curve);
120
120
121
121
return key;
122
122
}
123
123
124
- ffi. Pointer < EVP_PKEY > _importJwkEcPrivateOrPublicKey (
124
+ _EvpPKey _importJwkEcPrivateOrPublicKey (
125
125
JsonWebKey jwk,
126
126
EllipticCurve curve, {
127
127
required bool isPrivateKey,
@@ -212,16 +212,16 @@ ffi.Pointer<EVP_PKEY> _importJwkEcPrivateOrPublicKey(
212
212
_checkDataIsOne (ssl.EC_KEY_check_key (ec), fallback: 'invalid EC key' );
213
213
214
214
// Wrap with an EVP_KEY
215
- final key = _createEVP_PKEYwithFinalizer ();
216
- _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY (key, ec));
215
+ final key = _EvpPKey ();
216
+ _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY . invoke (key, ec));
217
217
218
218
return key;
219
219
} finally {
220
220
scope.release ();
221
221
}
222
222
}
223
223
224
- ffi. Pointer < EVP_PKEY > _importRawEcPublicKey (
224
+ _EvpPKey _importRawEcPublicKey (
225
225
List <int > keyData,
226
226
EllipticCurve curve,
227
227
) {
@@ -248,8 +248,8 @@ ffi.Pointer<EVP_PKEY> _importRawEcPublicKey(
248
248
_checkDataIsOne (ssl.EC_KEY_set_public_key (ec, pub),
249
249
fallback: 'invalid keyData' );
250
250
251
- final key = _createEVP_PKEYwithFinalizer ();
252
- _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY (key, ec));
251
+ final key = _EvpPKey ();
252
+ _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY . invoke (key, ec));
253
253
_validateEllipticCurveKey (key, curve);
254
254
255
255
return key;
@@ -261,10 +261,10 @@ ffi.Pointer<EVP_PKEY> _importRawEcPublicKey(
261
261
}
262
262
}
263
263
264
- Uint8List _exportRawEcPublicKey (ffi. Pointer < EVP_PKEY > key) {
264
+ Uint8List _exportRawEcPublicKey (_EvpPKey key) {
265
265
final scope = _Scope ();
266
266
try {
267
- final ec = ssl.EVP_PKEY_get1_EC_KEY (key);
267
+ final ec = ssl.EVP_PKEY_get1_EC_KEY . invoke (key);
268
268
_checkOp (ec.address != 0 , fallback: 'internal key type invariant error' );
269
269
scope.defer (() => ssl.EC_KEY_free (ec));
270
270
@@ -285,13 +285,13 @@ Uint8List _exportRawEcPublicKey(ffi.Pointer<EVP_PKEY> key) {
285
285
}
286
286
287
287
Map <String , dynamic > _exportJwkEcPrivateOrPublicKey (
288
- ffi. Pointer < EVP_PKEY > key, {
288
+ _EvpPKey key, {
289
289
required bool isPrivateKey,
290
290
String ? jwkUse,
291
291
}) {
292
292
final scope = _Scope ();
293
293
try {
294
- final ec = ssl.EVP_PKEY_get1_EC_KEY (key);
294
+ final ec = ssl.EVP_PKEY_get1_EC_KEY . invoke (key);
295
295
_checkOp (ec.address != 0 , fallback: 'internal key type invariant error' );
296
296
scope.defer (() => ssl.EC_KEY_free (ec));
297
297
@@ -340,7 +340,7 @@ Map<String, dynamic> _exportJwkEcPrivateOrPublicKey(
340
340
}
341
341
}
342
342
343
- KeyPair <ffi. Pointer < EVP_PKEY >, ffi. Pointer < EVP_PKEY > > _generateEcKeyPair (
343
+ KeyPair <_EvpPKey , _EvpPKey > _generateEcKeyPair (
344
344
EllipticCurve curve,
345
345
) {
346
346
final scope = _Scope ();
@@ -351,8 +351,8 @@ KeyPair<ffi.Pointer<EVP_PKEY>, ffi.Pointer<EVP_PKEY>> _generateEcKeyPair(
351
351
352
352
_checkOpIsOne (ssl.EC_KEY_generate_key (ecPriv));
353
353
354
- final privKey = _createEVP_PKEYwithFinalizer ();
355
- _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY (privKey, ecPriv));
354
+ final privKey = _EvpPKey ();
355
+ _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY . invoke (privKey, ecPriv));
356
356
357
357
final ecPub = ssl.EC_KEY_new_by_curve_name (_ecCurveToNID (curve));
358
358
_checkOp (ecPub.address != 0 );
@@ -362,8 +362,8 @@ KeyPair<ffi.Pointer<EVP_PKEY>, ffi.Pointer<EVP_PKEY>> _generateEcKeyPair(
362
362
ssl.EC_KEY_get0_public_key (ecPriv),
363
363
));
364
364
365
- final pubKey = _createEVP_PKEYwithFinalizer ();
366
- _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY (pubKey, ecPub));
365
+ final pubKey = _EvpPKey ();
366
+ _checkOpIsOne (ssl.EVP_PKEY_set1_EC_KEY . invoke (pubKey, ecPub));
367
367
368
368
return _KeyPair (
369
369
privateKey: privKey,
0 commit comments