Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.ec_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ KeyPair<_EvpPKey, _EvpPKey> _generateEcKeyPair(
final pubKey = _EvpPKey();
_checkOpIsOne(ssl.EVP_PKEY_set1_EC_KEY.invoke(pubKey, ecPub));

return createKeyPair(
privKey,
pubKey,
return (
privateKey: privKey,
publicKey: pubKey,
);
});
}
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Future<KeyPair<EcdhPrivateKeyImpl, EcdhPublicKeyImpl>>
EllipticCurve curve,
) async {
final p = _generateEcKeyPair(curve);
return createKeyPair(
_EcdhPrivateKeyImpl(p.privateKey),
_EcdhPublicKeyImpl(p.publicKey),
return (
privateKey: _EcdhPrivateKeyImpl(p.privateKey),
publicKey: _EcdhPublicKeyImpl(p.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ Future<KeyPair<EcdsaPrivateKeyImpl, EcdsaPublicKeyImpl>>
EllipticCurve curve,
) async {
final p = _generateEcKeyPair(curve);
return createKeyPair(
_EcdsaPrivateKeyImpl(p.privateKey),
_EcdsaPublicKeyImpl(p.publicKey),
return (
privateKey: _EcdsaPrivateKeyImpl(p.privateKey),
publicKey: _EcdsaPublicKeyImpl(p.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.rsa_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ KeyPair<_EvpPKey, _EvpPKey> _generateRsaKeyPair(
final pubKey = _EvpPKey();
_checkOp(ssl.EVP_PKEY_set1_RSA.invoke(pubKey, pubRSA) == 1);

return createKeyPair(
privKey,
pubKey,
return (
privateKey: privKey,
publicKey: pubKey,
);
});
}
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.rsaoaep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Future<KeyPair<RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl>>
// Get hash first, to avoid a leak of EVP_PKEY if _HashImpl.fromHash throws
final h = _HashImpl.fromHash(hash);
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
return createKeyPair(
_RsaOaepPrivateKeyImpl(keys.privateKey, h),
_RsaOaepPublicKeyImpl(keys.publicKey, h),
return (
privateKey: _RsaOaepPrivateKeyImpl(keys.privateKey, h),
publicKey: _RsaOaepPublicKeyImpl(keys.publicKey, h),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.rsapss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Future<KeyPair<RsaPssPrivateKeyImpl, RsaPssPublicKeyImpl>>
// Validate and get hash function
final h = _HashImpl.fromHash(hash);
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
return createKeyPair(
_RsaPssPrivateKeyImpl(keys.privateKey, h),
_RsaPssPublicKeyImpl(keys.publicKey, h),
return (
privateKey: _RsaPssPrivateKeyImpl(keys.privateKey, h),
publicKey: _RsaPssPublicKeyImpl(keys.publicKey, h),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Future<KeyPair<RsaSsaPkcs1V15PrivateKeyImpl, RsaSsaPkcs1V15PublicKeyImpl>>
// Get hash first, to avoid a leak of EVP_PKEY if _HashImpl.fromHash throws
final h = _HashImpl.fromHash(hash);
final keys = _generateRsaKeyPair(modulusLength, publicExponent);
return createKeyPair(
_RsaSsaPkcs1V15PrivateKeyImpl(keys.privateKey, h),
_RsaSsaPkcs1V15PublicKeyImpl(keys.publicKey, h),
return (
privateKey: _RsaSsaPkcs1V15PrivateKeyImpl(keys.privateKey, h),
publicKey: _RsaSsaPkcs1V15PublicKeyImpl(keys.publicKey, h),
);
}

Expand Down
15 changes: 1 addition & 14 deletions lib/src/impl_interface/impl_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,7 @@ part 'impl_interface.digest.dart';
part 'impl_interface.random.dart';

/// A key-pair as returned from key generation.
class KeyPair<S, T> {
KeyPair._(this.privateKey, this.publicKey); // keep the constructor private.

/// Private key for [publicKey].
final S privateKey;

/// Public key matching [privateKey].
final T publicKey;
}

/// Factory method to create KeyPair instance
KeyPair<S, T> createKeyPair<S, T>(S privateKey, T publicKey) {
return KeyPair._(privateKey, publicKey);
}
typedef KeyPair<T, S> = ({T privateKey, S publicKey});

/// Elliptic curves supported by ECDSA and ECDH.
///
Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_js/impl_js.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ Future<KeyPair<EcdhPrivateKeyImpl, EcdhPublicKeyImpl>>
),
_usagesDeriveBits,
);
return createKeyPair(
_EcdhPrivateKeyImpl(pair.privateKey),
_EcdhPublicKeyImpl(pair.publicKey),
return (
privateKey: _EcdhPrivateKeyImpl(pair.privateKey),
publicKey: _EcdhPublicKeyImpl(pair.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_js/impl_js.ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Future<KeyPair<EcdsaPrivateKeyImpl, EcdsaPublicKeyImpl>>
),
_usagesSignVerify,
);
return createKeyPair(
_EcdsaPrivateKeyImpl(pair.privateKey),
_EcdsaPublicKeyImpl(pair.publicKey),
return (
privateKey: _EcdsaPrivateKeyImpl(pair.privateKey),
publicKey: _EcdsaPublicKeyImpl(pair.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_js/impl_js.rsaoaep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Future<KeyPair<RsaOaepPrivateKeyImpl, RsaOaepPublicKeyImpl>>
),
_usagesEncryptDecrypt,
);
return createKeyPair(
_RsaOaepPrivateKeyImpl(pair.privateKey),
_RsaOaepPublicKeyImpl(pair.publicKey),
return (
privateKey: _RsaOaepPrivateKeyImpl(pair.privateKey),
publicKey: _RsaOaepPublicKeyImpl(pair.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_js/impl_js.rsapss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Future<KeyPair<RsaPssPrivateKeyImpl, RsaPssPublicKeyImpl>>
),
_usagesSignVerify,
);
return createKeyPair(
_RsaPssPrivateKeyImpl(pair.privateKey),
_RsaPssPublicKeyImpl(pair.publicKey),
return (
privateKey: _RsaPssPrivateKeyImpl(pair.privateKey),
publicKey: _RsaPssPublicKeyImpl(pair.publicKey),
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/impl_js/impl_js.rsassapkcs1v15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Future<KeyPair<RsaSsaPkcs1V15PrivateKeyImpl, RsaSsaPkcs1V15PublicKeyImpl>>
),
_usagesSignVerify,
);
return createKeyPair(
_RsaSsaPkcs1V15PrivateKeyImpl(pair.privateKey),
_RsaSsaPkcs1V15PublicKeyImpl(pair.publicKey),
return (
privateKey: _RsaSsaPkcs1V15PrivateKeyImpl(pair.privateKey),
publicKey: _RsaSsaPkcs1V15PublicKeyImpl(pair.publicKey),
);
}

Expand Down
47 changes: 22 additions & 25 deletions lib/src/testing/utils/testrunner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,7 @@ typedef DeriveBitsFn<T> = Future<List<int>> Function(
Map<String, dynamic> deriveParams,
);

class _KeyPair<S, T> implements KeyPair<S, T> {
@override
final S privateKey;

@override
final T publicKey;

_KeyPair({required this.privateKey, required this.publicKey});
}
typedef KeyPair<S, T> = ({S privateKey, T publicKey});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?


@sealed
class TestRunner<PrivateKey, PublicKey> {
Expand Down Expand Up @@ -402,7 +394,7 @@ class TestRunner<PrivateKey, PublicKey> {
exportPrivateJsonWebKey: exportPrivateJsonWebKey,
generateKeyPair: (params) async {
final k = await generateKey(params);
return _KeyPair(privateKey: k, publicKey: k);
return (privateKey: k, publicKey: k);
},
signBytes: signBytes,
signStream: signStream,
Expand Down Expand Up @@ -867,9 +859,10 @@ void _runTests<PrivateKey, PublicKey>(
} else {
test('create derivedBits', () async {
derivedBits = await r._deriveBits(
_KeyPair(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey),
(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey
),
c.derivedLength!,
c.deriveParams!,
);
Expand All @@ -878,9 +871,10 @@ void _runTests<PrivateKey, PublicKey>(

test('validated derivedBits', () async {
final derived = await r._deriveBits(
_KeyPair(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey),
(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey
),
c.derivedLength!,
c.deriveParams!,
);
Expand Down Expand Up @@ -983,9 +977,10 @@ void _runTests<PrivateKey, PublicKey>(
}
if (r._deriveBits != null) {
final derived = await r._deriveBits(
_KeyPair(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey),
(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey
),
c.derivedLength!,
c.deriveParams!,
);
Expand All @@ -1009,9 +1004,10 @@ void _runTests<PrivateKey, PublicKey>(
}
if (r._deriveBits != null) {
final derived = await r._deriveBits(
_KeyPair(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey),
(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey
),
c.derivedLength!,
c.deriveParams!,
);
Expand Down Expand Up @@ -1363,9 +1359,10 @@ void _runTests<PrivateKey, PublicKey>(
if (r._deriveBits != null) {
test('deriveBits', () async {
final derived = await r._deriveBits(
_KeyPair(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey),
(
privateKey: privateKey as PrivateKey,
publicKey: publicKey as PublicKey
),
c.derivedLength!,
c.deriveParams!,
);
Expand Down
13 changes: 2 additions & 11 deletions lib/src/testing/webcrypto/ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ import '../utils/utils.dart';
import '../utils/testrunner.dart';
import '../utils/detected_runtime.dart';

class _KeyPair<S extends EcdhPrivateKey, T extends EcdhPublicKey>
implements KeyPair<S, T> {
@override
final S privateKey;

@override
final T publicKey;

_KeyPair({required this.privateKey, required this.publicKey});
}
typedef KeyPair<S, T> = ({S privateKey, T publicKey});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?


final runner = TestRunner.asymmetric<EcdhPrivateKey, EcdhPublicKey>(
algorithm: 'ECDH',
Expand Down Expand Up @@ -58,7 +49,7 @@ final runner = TestRunner.asymmetric<EcdhPrivateKey, EcdhPublicKey>(
final b = await EcdhPrivateKey.generateKey(curveFromJson(
generateKeyPairParams,
));
return _KeyPair(
return (
privateKey: a.privateKey,
publicKey: b.publicKey,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class EcdhPrivateKey {
final privateKey = EcdhPrivateKey(privateKeyImpl);
final publicKey = EcdhPublicKey(publicKeyImpl);

return createKeyPair(privateKey, publicKey);
return (privateKey: privateKey, publicKey: publicKey);
}

/// Derive a shared secret from two ECDH key pairs using the private key from one pair
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webcrypto/webcrypto.ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class EcdsaPrivateKey {
final privateKey = EcdsaPrivateKey(privateKeyImpl);
final publicKey = EcdsaPublicKey(publicKeyImpl);

return createKeyPair(privateKey, publicKey);
return (privateKey: privateKey, publicKey: publicKey);
}

/// TODO: Document that this returns the raw signature format specified
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webcrypto/webcrypto.rsaoaep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ final class RsaOaepPrivateKey {
final privateKey = RsaOaepPrivateKey(privateKeyImpl);
final publicKey = RsaOaepPublicKey(publicKeyImpl);

return createKeyPair(privateKey, publicKey);
return (privateKey: privateKey, publicKey: publicKey);
}

/// Decrypt [data] encrypted with [RsaOaepPublicKey.encryptBytes] from the
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webcrypto/webcrypto.rsapss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ final class RsaPssPrivateKey {
final privateKey = RsaPssPrivateKey(privateKeyImpl);
final publicKey = RsaPssPublicKey(publicKeyImpl);

return createKeyPair(privateKey, publicKey);
return (privateKey: privateKey, publicKey: publicKey);
}

/// Sign [data] with this RSASSA-PSS private key.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webcrypto/webcrypto.rsassapkcs1v15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ final class RsassaPkcs1V15PrivateKey {
final privateKey = RsassaPkcs1V15PrivateKey(privateKeyImpl);
final publicKey = RsassaPkcs1V15PublicKey(publicKeyImpl);

return createKeyPair(privateKey, publicKey);
return (privateKey: privateKey, publicKey: publicKey);
}

/// Sign [data] with this RSASSA-PKCS1-v1_5 private key.
Expand Down
Loading