Skip to content

Commit d24e5cc

Browse files
Replace KeyPair class with record typedef KeyPair<T,S> (#195)
* refactor: replace keypair class with typedef * fix: remove unused declarations
1 parent 4ef7d30 commit d24e5cc

20 files changed

+64
-93
lines changed

lib/src/impl_ffi/impl_ffi.ec_common.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ KeyPair<_EvpPKey, _EvpPKey> _generateEcKeyPair(
351351
final pubKey = _EvpPKey();
352352
_checkOpIsOne(ssl.EVP_PKEY_set1_EC_KEY.invoke(pubKey, ecPub));
353353

354-
return createKeyPair(
355-
privKey,
356-
pubKey,
354+
return (
355+
privateKey: privKey,
356+
publicKey: pubKey,
357357
);
358358
});
359359
}

lib/src/impl_ffi/impl_ffi.ecdh.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Future<KeyPair<EcdhPrivateKeyImpl, EcdhPublicKeyImpl>>
3939
EllipticCurve curve,
4040
) async {
4141
final p = _generateEcKeyPair(curve);
42-
return createKeyPair(
43-
_EcdhPrivateKeyImpl(p.privateKey),
44-
_EcdhPublicKeyImpl(p.publicKey),
42+
return (
43+
privateKey: _EcdhPrivateKeyImpl(p.privateKey),
44+
publicKey: _EcdhPublicKeyImpl(p.publicKey),
4545
);
4646
}
4747

lib/src/impl_ffi/impl_ffi.ecdsa.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Future<KeyPair<EcdsaPrivateKeyImpl, EcdsaPublicKeyImpl>>
5555
EllipticCurve curve,
5656
) async {
5757
final p = _generateEcKeyPair(curve);
58-
return createKeyPair(
59-
_EcdsaPrivateKeyImpl(p.privateKey),
60-
_EcdsaPublicKeyImpl(p.publicKey),
58+
return (
59+
privateKey: _EcdsaPrivateKeyImpl(p.privateKey),
60+
publicKey: _EcdsaPublicKeyImpl(p.publicKey),
6161
);
6262
}
6363

lib/src/impl_ffi/impl_ffi.rsa_common.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
278278
final pubKey = _EvpPKey();
279279
_checkOp(ssl.EVP_PKEY_set1_RSA.invoke(pubKey, pubRSA) == 1);
280280

281-
return createKeyPair(
282-
privKey,
283-
pubKey,
281+
return (
282+
privateKey: privKey,
283+
publicKey: pubKey,
284284
);
285285
});
286286
}

lib/src/impl_ffi/impl_ffi.rsaoaep.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Future<KeyPair<RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl>>
5151
// Get hash first, to avoid a leak of EVP_PKEY if _HashImpl.fromHash throws
5252
final h = _HashImpl.fromHash(hash);
5353
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
54-
return createKeyPair(
55-
_RsaOaepPrivateKeyImpl(keys.privateKey, h),
56-
_RsaOaepPublicKeyImpl(keys.publicKey, h),
54+
return (
55+
privateKey: _RsaOaepPrivateKeyImpl(keys.privateKey, h),
56+
publicKey: _RsaOaepPublicKeyImpl(keys.publicKey, h),
5757
);
5858
}
5959

lib/src/impl_ffi/impl_ffi.rsapss.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Future<KeyPair<RsaPssPrivateKeyImpl, RsaPssPublicKeyImpl>>
5151
// Validate and get hash function
5252
final h = _HashImpl.fromHash(hash);
5353
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
54-
return createKeyPair(
55-
_RsaPssPrivateKeyImpl(keys.privateKey, h),
56-
_RsaPssPublicKeyImpl(keys.publicKey, h),
54+
return (
55+
privateKey: _RsaPssPrivateKeyImpl(keys.privateKey, h),
56+
publicKey: _RsaPssPublicKeyImpl(keys.publicKey, h),
5757
);
5858
}
5959

lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Future<KeyPair<RsaSsaPkcs1V15PrivateKeyImpl, RsaSsaPkcs1V15PublicKeyImpl>>
5151
// Get hash first, to avoid a leak of EVP_PKEY if _HashImpl.fromHash throws
5252
final h = _HashImpl.fromHash(hash);
5353
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
54-
return createKeyPair(
55-
_RsaSsaPkcs1V15PrivateKeyImpl(keys.privateKey, h),
56-
_RsaSsaPkcs1V15PublicKeyImpl(keys.publicKey, h),
54+
return (
55+
privateKey: _RsaSsaPkcs1V15PrivateKeyImpl(keys.privateKey, h),
56+
publicKey: _RsaSsaPkcs1V15PublicKeyImpl(keys.publicKey, h),
5757
);
5858
}
5959

lib/src/impl_interface/impl_interface.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,7 @@ part 'impl_interface.digest.dart';
3434
part 'impl_interface.random.dart';
3535

3636
/// A key-pair as returned from key generation.
37-
class KeyPair<S, T> {
38-
KeyPair._(this.privateKey, this.publicKey); // keep the constructor private.
39-
40-
/// Private key for [publicKey].
41-
final S privateKey;
42-
43-
/// Public key matching [privateKey].
44-
final T publicKey;
45-
}
46-
47-
/// Factory method to create KeyPair instance
48-
KeyPair<S, T> createKeyPair<S, T>(S privateKey, T publicKey) {
49-
return KeyPair._(privateKey, publicKey);
50-
}
37+
typedef KeyPair<T, S> = ({T privateKey, S publicKey});
5138

5239
/// Elliptic curves supported by ECDSA and ECDH.
5340
///

lib/src/impl_js/impl_js.ecdh.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ Future<KeyPair<EcdhPrivateKeyImpl, EcdhPublicKeyImpl>>
6666
),
6767
_usagesDeriveBits,
6868
);
69-
return createKeyPair(
70-
_EcdhPrivateKeyImpl(pair.privateKey),
71-
_EcdhPublicKeyImpl(pair.publicKey),
69+
return (
70+
privateKey: _EcdhPrivateKeyImpl(pair.privateKey),
71+
publicKey: _EcdhPublicKeyImpl(pair.publicKey),
7272
);
7373
}
7474

lib/src/impl_js/impl_js.ecdsa.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Future<KeyPair<EcdsaPrivateKeyImpl, EcdsaPublicKeyImpl>>
6060
),
6161
_usagesSignVerify,
6262
);
63-
return createKeyPair(
64-
_EcdsaPrivateKeyImpl(pair.privateKey),
65-
_EcdsaPublicKeyImpl(pair.publicKey),
63+
return (
64+
privateKey: _EcdsaPrivateKeyImpl(pair.privateKey),
65+
publicKey: _EcdsaPublicKeyImpl(pair.publicKey),
6666
);
6767
}
6868

0 commit comments

Comments
 (0)