@@ -33,8 +33,6 @@ int _ecCurveToNID(EllipticCurve curve) {
33
33
34
34
/// Get [EllipticCurve] from matching BoringSSL `ssl.NID_...` .
35
35
EllipticCurve _ecCurveFromNID (int nid) {
36
- assert (nid != null );
37
-
38
36
if (nid == ssl.NID_X9_62_prime256v1 ) {
39
37
return EllipticCurve .p256;
40
38
}
@@ -126,17 +124,22 @@ ffi.Pointer<ssl.EVP_PKEY> _importSpkiEcPublicKey(
126
124
ffi.Pointer <ssl.EVP_PKEY > _importJwkEcPrivateOrPublicKey (
127
125
JsonWebKey jwk,
128
126
EllipticCurve curve, {
129
- @ required bool isPrivateKey,
130
- @ required String expectedUse,
131
- String expectedAlg, // may be null, if 'alg' property isn't validated (ECDH)
127
+ required bool isPrivateKey,
128
+ required String expectedUse,
129
+ String ? expectedAlg, // may be null, if 'alg' property isn't validated (ECDH)
132
130
}) {
133
- assert (isPrivateKey != null );
134
- assert (expectedUse != null );
135
-
136
131
_checkData (
137
132
jwk.kty == 'EC' ,
138
133
message: 'expected a elliptic-curve key, JWK property "kty" must be "EC"' ,
139
134
);
135
+ _checkData (
136
+ jwk.x != null ,
137
+ message: 'expected a elliptic-curve key, JWK property "x" to be present' ,
138
+ );
139
+ _checkData (
140
+ jwk.y != null ,
141
+ message: 'expected a elliptic-curve key, JWK property "y" to be present' ,
142
+ );
140
143
if (isPrivateKey) {
141
144
_checkData (
142
145
jwk.d != null ,
@@ -193,15 +196,15 @@ ffi.Pointer<ssl.EVP_PKEY> _importJwkEcPrivateOrPublicKey(
193
196
_checkDataIsOne (
194
197
ssl.EC_KEY_set_public_key_affine_coordinates (
195
198
ec,
196
- decodeParam (jwk.x, 'x' ),
197
- decodeParam (jwk.y, 'y' ),
199
+ decodeParam (jwk.x! , 'x' ),
200
+ decodeParam (jwk.y! , 'y' ),
198
201
),
199
202
fallback: 'invalid EC key' ,
200
203
);
201
204
202
205
if (isPrivateKey) {
203
206
_checkDataIsOne (
204
- ssl.EC_KEY_set_private_key (ec, decodeParam (jwk.d, 'd' )),
207
+ ssl.EC_KEY_set_private_key (ec, decodeParam (jwk.d! , 'd' )),
205
208
fallback: 'invalid EC key' ,
206
209
);
207
210
}
@@ -262,7 +265,7 @@ Uint8List _exportRawEcPublicKey(ffi.Pointer<ssl.EVP_PKEY> key) {
262
265
final scope = _Scope ();
263
266
try {
264
267
final ec = ssl.EVP_PKEY_get1_EC_KEY (key);
265
- _checkOp (ec.address != null , fallback: 'internal key type invariant error' );
268
+ _checkOp (ec.address != 0 , fallback: 'internal key type invariant error' );
266
269
scope.defer (() => ssl.EC_KEY_free (ec));
267
270
268
271
return _withOutCBB ((cbb) {
@@ -283,11 +286,9 @@ Uint8List _exportRawEcPublicKey(ffi.Pointer<ssl.EVP_PKEY> key) {
283
286
284
287
Map <String , dynamic > _exportJwkEcPrivateOrPublicKey (
285
288
ffi.Pointer <ssl.EVP_PKEY > key, {
286
- @ required bool isPrivateKey,
287
- String jwkUse,
289
+ required bool isPrivateKey,
290
+ String ? jwkUse,
288
291
}) {
289
- assert (isPrivateKey != null );
290
-
291
292
final scope = _Scope ();
292
293
try {
293
294
final ec = ssl.EVP_PKEY_get1_EC_KEY (key);
@@ -318,7 +319,7 @@ Map<String, dynamic> _exportJwkEcPrivateOrPublicKey(
318
319
_checkOpIsOne (ssl.BN_bn2bin_padded (p, paramSize, y));
319
320
});
320
321
321
- Uint8List dAsBytes;
322
+ Uint8List ? dAsBytes;
322
323
if (isPrivateKey) {
323
324
final d = ssl.EC_KEY_get0_private_key (ec);
324
325
dAsBytes = _withOutPointer (paramSize, (ffi.Pointer <ssl.Bytes > p) {
@@ -332,7 +333,7 @@ Map<String, dynamic> _exportJwkEcPrivateOrPublicKey(
332
333
crv: _ecCurveToJwkCrv (curve),
333
334
x: _jwkEncodeBase64UrlNoPadding (xAsBytes),
334
335
y: _jwkEncodeBase64UrlNoPadding (yAsBytes),
335
- d: isPrivateKey ? _jwkEncodeBase64UrlNoPadding (dAsBytes) : null ,
336
+ d: dAsBytes != null ? _jwkEncodeBase64UrlNoPadding (dAsBytes) : null ,
336
337
).toJson ();
337
338
} finally {
338
339
scope.release ();
0 commit comments