diff --git a/cryptography/lib/src/browser/_javascript_bindings.dart b/cryptography/lib/src/browser/_javascript_bindings.dart index 7d83ab3..8f005a9 100644 --- a/cryptography/lib/src/browser/_javascript_bindings.dart +++ b/cryptography/lib/src/browser/_javascript_bindings.dart @@ -16,8 +16,8 @@ library web_crypto_api; import 'dart:convert' show base64Url; -import 'dart:html' show CryptoKey; import 'dart:html' as html; +import 'dart:html' show CryptoKey; import 'dart:typed_data'; import 'package:js/js.dart'; @@ -26,8 +26,7 @@ import 'package:js/js_util.dart' show promiseToFuture; export 'dart:html' show CryptoKey; /// Note that browsers support Web Cryptography only in secure contexts. -final bool isWebCryptoAvailable = - _subtle != null && (html.window.isSecureContext ?? false); +final bool isWebCryptoAvailable = _subtle != null && (html.window.isSecureContext ?? false); @JS('crypto.subtle') external Object? get _subtle; @@ -203,9 +202,7 @@ Future importKeyWhenRaw( ByteBuffer jsArrayBufferFrom(List data) { // Avoid copying if possible // - if (data is Uint8List && - data.offsetInBytes == 0 && - data.lengthInBytes == data.buffer.lengthInBytes) { + if (data is Uint8List && data.offsetInBytes == 0 && data.lengthInBytes == data.buffer.lengthInBytes) { // We need to check the type because UnmodifiableByteBufferView would cause // an error. final buffer = data.buffer; diff --git a/cryptography/lib/src/browser/aes_cbc.dart b/cryptography/lib/src/browser/aes_cbc.dart index 0e8a069..e8f6aa5 100644 --- a/cryptography/lib/src/browser/aes_cbc.dart +++ b/cryptography/lib/src/browser/aes_cbc.dart @@ -17,8 +17,8 @@ import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; -import '_javascript_bindings.dart' show jsArrayBufferFrom; import '_javascript_bindings.dart' as web_crypto; +import '_javascript_bindings.dart' show jsArrayBufferFrom; import 'browser_secret_key.dart'; /// AES-CBC implementation that uses _Web Cryptography API_ in browsers. @@ -38,9 +38,9 @@ class BrowserAesCbc extends AesCbc { const BrowserAesCbc({ required this.macAlgorithm, this.secretKeyLength = 32, - Random? random, + super.random, }) : _random = random, - super.constructor(random: random); + super.constructor(); @override PaddingAlgorithm get paddingAlgorithm => PaddingAlgorithm.pkcs7; diff --git a/cryptography/lib/src/browser/aes_ctr.dart b/cryptography/lib/src/browser/aes_ctr.dart index 68c65f0..b746545 100644 --- a/cryptography/lib/src/browser/aes_ctr.dart +++ b/cryptography/lib/src/browser/aes_ctr.dart @@ -17,8 +17,8 @@ import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; -import '_javascript_bindings.dart' show jsArrayBufferFrom; import '_javascript_bindings.dart' as web_crypto; +import '_javascript_bindings.dart' show jsArrayBufferFrom; import 'browser_secret_key.dart'; /// AES-CTR implementation that uses _Web Cryptography API_ in browsers. @@ -40,9 +40,9 @@ class BrowserAesCtr extends AesCtr { required this.macAlgorithm, this.secretKeyLength = 32, this.counterBits = 64, - Random? random, + super.random, }) : _random = random, - super.constructor(random: random); + super.constructor(); @override Future> decrypt( diff --git a/cryptography/lib/src/browser/aes_gcm.dart b/cryptography/lib/src/browser/aes_gcm.dart index 44aa5be..142f909 100644 --- a/cryptography/lib/src/browser/aes_gcm.dart +++ b/cryptography/lib/src/browser/aes_gcm.dart @@ -19,8 +19,8 @@ import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; import 'package:cryptography_plus/src/browser/browser_secret_key.dart'; -import '_javascript_bindings.dart' show jsArrayBufferFrom; import '_javascript_bindings.dart' as web_crypto; +import '_javascript_bindings.dart' show jsArrayBufferFrom; /// AES-GCM implementation that uses _Web Cryptography API_ in browsers. class BrowserAesGcm extends AesGcm implements StreamingCipher { @@ -43,9 +43,9 @@ class BrowserAesGcm extends AesGcm implements StreamingCipher { this.secretKeyLength = 32, this.nonceLength = AesGcm.defaultNonceLength, this.fallback, - Random? random, + super.random, }) : _random = random, - super.constructor(random: random); + super.constructor(); @override Future> decrypt( diff --git a/cryptography/lib/src/browser/browser_cryptography.dart b/cryptography/lib/src/browser/browser_cryptography.dart index 298de18..55c9561 100644 --- a/cryptography/lib/src/browser/browser_cryptography.dart +++ b/cryptography/lib/src/browser/browser_cryptography.dart @@ -33,8 +33,7 @@ import 'pbkdf2.dart'; class BrowserCryptography extends DartCryptography { // Documented in browser_cryptography_when_not_browser.dart - static final Cryptography defaultInstance = - isSupported ? BrowserCryptography() : DartCryptography(); + static final Cryptography defaultInstance = isSupported ? BrowserCryptography() : DartCryptography(); /// @nodoc // TODO: Remove this @@ -48,9 +47,8 @@ class BrowserCryptography extends DartCryptography { // Documented in browser_cryptography_when_not_browser.dart BrowserCryptography({ - Random? random, - }) : _random = random, - super(random: random); + super.random, + }) : _random = random; @override AesCbc aesCbc({ @@ -59,9 +57,7 @@ class BrowserCryptography extends DartCryptography { int secretKeyLength = 32, }) { // Web Cryptography API supports only 128 and 256 bit keys. - if (isSupported && - secretKeyLength != 24 && - identical(paddingAlgorithm, PaddingAlgorithm.pkcs7)) { + if (isSupported && secretKeyLength != 24 && identical(paddingAlgorithm, PaddingAlgorithm.pkcs7)) { return BrowserAesCbc( macAlgorithm: macAlgorithm, secretKeyLength: secretKeyLength, @@ -184,8 +180,7 @@ class BrowserCryptography extends DartCryptography { @override Hkdf hkdf({required Hmac hmac, required int outputLength}) { if (isSupported) { - if (BrowserHashAlgorithmMixin.hashAlgorithmNameFor(hmac.hashAlgorithm) != - null) { + if (BrowserHashAlgorithmMixin.hashAlgorithmNameFor(hmac.hashAlgorithm) != null) { return BrowserHkdf( hmac: hmac, outputLength: outputLength, diff --git a/cryptography/lib/src/browser/browser_cryptography_when_not_browser.dart b/cryptography/lib/src/browser/browser_cryptography_when_not_browser.dart index 586d1b5..4c0c9e5 100644 --- a/cryptography/lib/src/browser/browser_cryptography_when_not_browser.dart +++ b/cryptography/lib/src/browser/browser_cryptography_when_not_browser.dart @@ -81,7 +81,7 @@ class BrowserCryptography extends DartCryptography { /// /// If [random] is not given, algorithms will use some cryptographically /// secure random number generator (CSRNG) such as [Random.secure]. - BrowserCryptography({Random? random}) : super(random: random); + BrowserCryptography({super.random}); @override BrowserCryptography withRandom(Random? random) { diff --git a/cryptography/lib/src/browser/rsa_pss.dart b/cryptography/lib/src/browser/rsa_pss.dart index 2932dc7..61786a5 100644 --- a/cryptography/lib/src/browser/rsa_pss.dart +++ b/cryptography/lib/src/browser/rsa_pss.dart @@ -17,13 +17,9 @@ import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; -import '_javascript_bindings.dart' as web_crypto; import '_javascript_bindings.dart' - show - base64UrlDecodeUnmodifiable, - base64UrlDecodeUnmodifiableMaybe, - base64UrlEncode, - base64UrlEncodeMaybe; + show base64UrlDecodeUnmodifiable, base64UrlDecodeUnmodifiableMaybe, base64UrlEncode, base64UrlEncodeMaybe; +import '_javascript_bindings.dart' as web_crypto; import 'hash.dart'; /// RSA-PSS implementation that uses _Web Cryptography API_ in browsers. @@ -272,7 +268,7 @@ class _BrowserRsaPublicKey extends RsaPublicKey { required this.jsCryptoKey, required this.webCryptoAlgorithm, required this.webCryptoHash, - required List n, - required List e, - }) : super(n: n, e: e); + required super.n, + required super.e, + }); } diff --git a/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart b/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart index 7b6cf23..252c7e8 100644 --- a/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart +++ b/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart @@ -18,8 +18,7 @@ import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; import '_javascript_bindings.dart' as web_crypto; -import '_javascript_bindings.dart' - show base64UrlDecodeUnmodifiable, base64UrlEncode, base64UrlEncodeMaybe; +import '_javascript_bindings.dart' show base64UrlDecodeUnmodifiable, base64UrlEncode, base64UrlEncodeMaybe; import 'hash.dart'; /// RSA-SSA-PKCS1v15 implementation that uses _Web Cryptography API_ in browsers. @@ -209,9 +208,9 @@ class _BrowserRsaPublicKey extends RsaPublicKey { required this.jsCryptoKey, required this.webCryptoAlgorithm, required this.webCryptoHash, - required List n, - required List e, - }) : super(n: n, e: e); + required super.n, + required super.e, + }); } class _BrowserRsaSsaPkcs1v15KeyPair extends KeyPair implements RsaKeyPair { diff --git a/cryptography/lib/src/cryptography/algorithms.dart b/cryptography/lib/src/cryptography/algorithms.dart index d9b6b8a..8e60a03 100644 --- a/cryptography/lib/src/cryptography/algorithms.dart +++ b/cryptography/lib/src/cryptography/algorithms.dart @@ -66,8 +66,8 @@ abstract class AesCbc extends Cipher { /// Constructor for classes that extend this class. const AesCbc.constructor({ - Random? random, - }) : super(random: random); + super.random, + }); /// Constructs 128-bit AES-CBC. factory AesCbc.with128bits({ @@ -215,7 +215,7 @@ abstract class AesCtr extends StreamingCipher { static const int defaultCounterBits = 64; /// Constructor for classes that extend this class. - const AesCtr.constructor({Random? random}) : super(random: random); + const AesCtr.constructor({super.random}); /// Constructs 128-bit AES-CTR. factory AesCtr.with128bits({ @@ -268,9 +268,7 @@ abstract class AesCtr extends StreamingCipher { @override bool operator ==(other) => - other is AesCtr && - secretKeyLength == other.secretKeyLength && - macAlgorithm == other.macAlgorithm; + other is AesCtr && secretKeyLength == other.secretKeyLength && macAlgorithm == other.macAlgorithm; @override void checkParameters({ @@ -368,7 +366,7 @@ abstract class AesGcm extends Cipher { static const int defaultNonceLength = 12; /// Constructor for classes that extend this class. - const AesGcm.constructor({Random? random}) : super(random: random); + const AesGcm.constructor({super.random}); factory AesGcm.with128bits({ int nonceLength = AesGcm.defaultNonceLength, @@ -418,9 +416,7 @@ abstract class AesGcm extends Cipher { @override bool operator ==(other) => - other is AesGcm && - secretKeyLength == other.secretKeyLength && - nonceLength == other.nonceLength; + other is AesGcm && secretKeyLength == other.secretKeyLength && nonceLength == other.nonceLength; @override String toString() { @@ -878,7 +874,7 @@ abstract class Chacha20 extends StreamingCipher { /// Constructor for classes that extend this class. /// /// Optional parameter [random] is used by [newSecretKey] and [newNonce]. - const Chacha20.constructor({Random? random}) : super(random: random); + const Chacha20.constructor({super.random}); /// Constructs ChaCha20-Poly1305-AEAD cipher /// (([RFC 7539](https://tools.ietf.org/html/rfc7539), also known as @@ -936,8 +932,7 @@ abstract class Chacha20 extends StreamingCipher { int get secretKeyLength => 32; @override - bool operator ==(other) => - other is Chacha20 && macAlgorithm == other.macAlgorithm; + bool operator ==(other) => other is Chacha20 && macAlgorithm == other.macAlgorithm; @override String toString() { @@ -1127,8 +1122,7 @@ abstract class Ecdsa extends SignatureAlgorithm { Future newKeyPairFromSeed(List seed); @override - String toString() => - '$runtimeType.p${keyPairType.ellipticBits}($hashAlgorithm)'; + String toString() => '$runtimeType.p${keyPairType.ellipticBits}($hashAlgorithm)'; } /// _Ed25519_ ([RFC 8032](https://tools.ietf.org/html/rfc8032)) signature @@ -1284,8 +1278,7 @@ abstract class Hkdf extends KdfAlgorithm { int get outputLength; @override - bool operator ==(other) => - other is Hkdf && hmac == other.hmac && outputLength == other.outputLength; + bool operator ==(other) => other is Hkdf && hmac == other.hmac && outputLength == other.outputLength; @override Future deriveKey({ @@ -1415,8 +1408,7 @@ abstract class Hmac extends MacAlgorithm { int get macLength => hashAlgorithm.hashLengthInBytes; @override - bool operator ==(other) => - other is Hmac && hashAlgorithm == other.hashAlgorithm; + bool operator ==(other) => other is Hmac && hashAlgorithm == other.hashAlgorithm; @override String toString() { @@ -1532,10 +1524,7 @@ abstract class Pbkdf2 extends KdfAlgorithm { @override bool operator ==(other) => - other is Pbkdf2 && - iterations == other.iterations && - bits == other.bits && - macAlgorithm == other.macAlgorithm; + other is Pbkdf2 && iterations == other.iterations && bits == other.bits && macAlgorithm == other.macAlgorithm; @override String toString() { @@ -1686,9 +1675,7 @@ abstract class RsaPss extends SignatureAlgorithm { @override bool operator ==(other) => - other is RsaPss && - hashAlgorithm == other.hashAlgorithm && - nonceLengthInBytes == other.nonceLengthInBytes; + other is RsaPss && hashAlgorithm == other.hashAlgorithm && nonceLengthInBytes == other.nonceLengthInBytes; @override Future newKeyPair({ @@ -1697,8 +1684,7 @@ abstract class RsaPss extends SignatureAlgorithm { }); @override - String toString() => - '$runtimeType($hashAlgorithm, nonceLengthInBytes: $nonceLengthInBytes)'; + String toString() => '$runtimeType($hashAlgorithm, nonceLengthInBytes: $nonceLengthInBytes)'; } /// _RSA-SSA-PKCS1v15_ [SignatureAlgorithm]. @@ -1770,8 +1756,7 @@ abstract class RsaSsaPkcs1v15 extends SignatureAlgorithm { KeyPairType get keyPairType => KeyPairType.rsa; @override - bool operator ==(other) => - other is RsaSsaPkcs1v15 && hashAlgorithm == other.hashAlgorithm; + bool operator ==(other) => other is RsaSsaPkcs1v15 && hashAlgorithm == other.hashAlgorithm; @override Future newKeyPair({ @@ -2107,7 +2092,7 @@ abstract class StreamingCipher extends Cipher { /// Constructor for subclasses. /// /// Optional parameter [random] is used by [newSecretKey] and [newNonce]. - const StreamingCipher({Random? random}) : super(random: random); + const StreamingCipher({super.random}); /// Decrypts a ciphertext. /// @@ -2231,7 +2216,7 @@ abstract class Xchacha20 extends StreamingCipher { } /// Constructor for classes that extend this class. - const Xchacha20.constructor({Random? random}) : super(random: random); + const Xchacha20.constructor({super.random}); /// _XAEAD_CHACHA20_POLY1305_ ([draft-irtf-cfrg-xchacha](https://tools.ietf.org/html/draft-arciszewski-xchacha-03)) cipher. /// @@ -2251,8 +2236,7 @@ abstract class Xchacha20 extends StreamingCipher { int get secretKeyLength => 32; @override - bool operator ==(other) => - other is Xchacha20 && macAlgorithm == other.macAlgorithm; + bool operator ==(other) => other is Xchacha20 && macAlgorithm == other.macAlgorithm; @override String toString() { diff --git a/cryptography/lib/src/cryptography/ec_key_pair.dart b/cryptography/lib/src/cryptography/ec_key_pair.dart index 19592eb..7664b14 100644 --- a/cryptography/lib/src/cryptography/ec_key_pair.dart +++ b/cryptography/lib/src/cryptography/ec_key_pair.dart @@ -79,15 +79,14 @@ class EcKeyPairData extends KeyPairData implements EcKeyPair { required List d, required this.x, required this.y, - required KeyPairType type, + required super.type, this.debugLabel, }) : _d = SensitiveBytes(d), publicKey = EcPublicKey( x: x, y: y, type: type, - ), - super(type: type); + ); /// Elliptic curve private key component `d` (confidential). List get d { @@ -99,10 +98,7 @@ class EcKeyPairData extends KeyPairData implements EcKeyPair { } @override - int get hashCode => - type.hashCode ^ - constantTimeBytesEquality.hash(x) ^ - constantTimeBytesEquality.hash(y); + int get hashCode => type.hashCode ^ constantTimeBytesEquality.hash(x) ^ constantTimeBytesEquality.hash(y); @override bool operator ==(other) { @@ -252,8 +248,7 @@ class EcKeyPairData extends KeyPairData implements EcKeyPair { ); } - static List _ensureNumberLength( - List bytes, int length, String name) { + static List _ensureNumberLength(List bytes, int length, String name) { if (bytes.length == length) { return bytes; } diff --git a/cryptography/lib/src/dart/aes_impl.dart b/cryptography/lib/src/dart/aes_impl.dart index 6e14c8d..3a8d68b 100644 --- a/cryptography/lib/src/dart/aes_impl.dart +++ b/cryptography/lib/src/dart/aes_impl.dart @@ -66,22 +66,10 @@ void aesDecryptBlock( var keyIndex = 4; final rounds = key.length ~/ 4 - 1; for (var round = 1; round < rounds; round++) { - final t0 = c0[0xFF & (v0 >> 24)] ^ - c1[0xFF & (v3 >> 16)] ^ - c2[0xFF & (v2 >> 8)] ^ - c3[0xFF & v1]; - final t1 = c0[0xFF & (v1 >> 24)] ^ - c1[0xFF & (v0 >> 16)] ^ - c2[0xFF & (v3 >> 8)] ^ - c3[0xFF & (v2 >> 0)]; - final t2 = c0[0xFF & (v2 >> 24)] ^ - c1[0xFF & (v1 >> 16)] ^ - c2[0xFF & (v0 >> 8)] ^ - c3[0xFF & (v3 >> 0)]; - final t3 = c0[0xFF & (v3 >> 24)] ^ - c1[0xFF & (v2 >> 16)] ^ - c2[0xFF & (v1 >> 8)] ^ - c3[0xFF & (v0 >> 0)]; + final t0 = c0[0xFF & (v0 >> 24)] ^ c1[0xFF & (v3 >> 16)] ^ c2[0xFF & (v2 >> 8)] ^ c3[0xFF & v1]; + final t1 = c0[0xFF & (v1 >> 24)] ^ c1[0xFF & (v0 >> 16)] ^ c2[0xFF & (v3 >> 8)] ^ c3[0xFF & (v2 >> 0)]; + final t2 = c0[0xFF & (v2 >> 24)] ^ c1[0xFF & (v1 >> 16)] ^ c2[0xFF & (v0 >> 8)] ^ c3[0xFF & (v3 >> 0)]; + final t3 = c0[0xFF & (v3 >> 24)] ^ c1[0xFF & (v2 >> 16)] ^ c2[0xFF & (v1 >> 8)] ^ c3[0xFF & (v0 >> 0)]; v0 = t0 ^ key[keyIndex + 0]; v1 = t1 ^ key[keyIndex + 1]; v2 = t2 ^ key[keyIndex + 2]; @@ -158,26 +146,13 @@ void aesEncryptBlock( var keyIndex = 4; final rounds = key.length ~/ 4 - 1; for (var round = 1; round < rounds; round++) { - final t0 = c0[0xFF & (v0 >> 24)] ^ - c1[0xFF & (v1 >> 16)] ^ - c2[0xFF & (v2 >> 8)] ^ - c3[0xFF & v3] ^ - key[keyIndex + 0]; - final t1 = c0[0xFF & (v1 >> 24)] ^ - c1[0xFF & (v2 >> 16)] ^ - c2[0xFF & (v3 >> 8)] ^ - c3[0xFF & (v0 >> 0)] ^ - key[keyIndex + 1]; - final t2 = c0[0xFF & (v2 >> 24)] ^ - c1[0xFF & (v3 >> 16)] ^ - c2[0xFF & (v0 >> 8)] ^ - c3[0xFF & (v1 >> 0)] ^ - key[keyIndex + 2]; - final t3 = c0[0xFF & (v3 >> 24)] ^ - c1[0xFF & (v0 >> 16)] ^ - c2[0xFF & (v1 >> 8)] ^ - c3[0xFF & (v2 >> 0)] ^ - key[keyIndex + 3]; + final t0 = c0[0xFF & (v0 >> 24)] ^ c1[0xFF & (v1 >> 16)] ^ c2[0xFF & (v2 >> 8)] ^ c3[0xFF & v3] ^ key[keyIndex + 0]; + final t1 = + c0[0xFF & (v1 >> 24)] ^ c1[0xFF & (v2 >> 16)] ^ c2[0xFF & (v3 >> 8)] ^ c3[0xFF & (v0 >> 0)] ^ key[keyIndex + 1]; + final t2 = + c0[0xFF & (v2 >> 24)] ^ c1[0xFF & (v3 >> 16)] ^ c2[0xFF & (v0 >> 8)] ^ c3[0xFF & (v1 >> 0)] ^ key[keyIndex + 2]; + final t3 = + c0[0xFF & (v3 >> 24)] ^ c1[0xFF & (v0 >> 16)] ^ c2[0xFF & (v1 >> 8)] ^ c3[0xFF & (v2 >> 0)] ^ key[keyIndex + 3]; v0 = t0; v1 = t1; v2 = t2; @@ -241,10 +216,7 @@ Uint32List aesExpandKeyForDecrypting(SecretKeyData secretKeyData) { for (var j = 0; j < 4; j++) { var value = encryptingKey[encryptionKeyIndex + j]; if (i > 0 && i < result.length - 4) { - value = d0[s[value >> 24]] ^ - d1[s[0xFF & (value >> 16)]] ^ - d2[s[0xFF & (value >> 8)]] ^ - d3[s[0xFF & value]]; + value = d0[s[value >> 24]] ^ d1[s[0xFF & (value >> 16)]] ^ d2[s[0xFF & (value >> 8)]] ^ d3[s[0xFF & value]]; } result[i + j] = value; } @@ -356,9 +328,9 @@ class _DartAesSecretKeyData extends SecretKeyData { Uint32List? _expandedBytesForDecrypting; _DartAesSecretKeyData( - List bytes, { - bool overwriteWhenDestroyed = false, - }) : super(bytes, overwriteWhenDestroyed: overwriteWhenDestroyed); + super.bytes, { + super.overwriteWhenDestroyed, + }); @override void destroy() { diff --git a/cryptography/lib/src/dart/ed25519.dart b/cryptography/lib/src/dart/ed25519.dart index f970146..b9938af 100644 --- a/cryptography/lib/src/dart/ed25519.dart +++ b/cryptography/lib/src/dart/ed25519.dart @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:math'; import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; @@ -29,9 +28,9 @@ class DartEd25519 extends Ed25519 { DartEd25519({ Sha512? sha512, - Random? random, + super.random, }) : _sha512 = sha512 ?? Sha512(), - super.constructor(random: random); + super.constructor(); @override KeyPairType get keyPairType => KeyPairType.ed25519; diff --git a/cryptography/lib/src/dart/x25519.dart b/cryptography/lib/src/dart/x25519.dart index a1d86f9..5d40480 100644 --- a/cryptography/lib/src/dart/x25519.dart +++ b/cryptography/lib/src/dart/x25519.dart @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:math'; import 'dart:typed_data'; import 'package:cryptography_plus/cryptography_plus.dart'; @@ -41,7 +40,7 @@ class DartX25519 extends X25519 with DartKeyExchangeAlgorithmMixin { }(); // Constant 121665 (0x1db41). - const DartX25519({Random? random}) : super.constructor(random: random); + const DartX25519({super.random}) : super.constructor(); @override KeyPairType get keyPairType => KeyPairType.x25519; @@ -61,15 +60,13 @@ class DartX25519 extends X25519 with DartKeyExchangeAlgorithmMixin { required KeyPairData keyPairData, required PublicKey remotePublicKey, }) { - if (keyPairData is! SimpleKeyPairData || - !KeyPairType.x25519.isValidKeyPairData(keyPairData)) { + if (keyPairData is! SimpleKeyPairData || !KeyPairType.x25519.isValidKeyPairData(keyPairData)) { throw ArgumentError.value( keyPairData, 'keyPairData', ); } - if (remotePublicKey is! SimplePublicKey || - !KeyPairType.x25519.isValidPublicKey(remotePublicKey)) { + if (remotePublicKey is! SimplePublicKey || !KeyPairType.x25519.isValidPublicKey(remotePublicKey)) { throw ArgumentError.value( remotePublicKey, 'remotePublicKey', diff --git a/cryptography/pubspec.yaml b/cryptography/pubspec.yaml index 3d03501..3ba8143 100644 --- a/cryptography/pubspec.yaml +++ b/cryptography/pubspec.yaml @@ -14,16 +14,17 @@ dependencies: # # Packages by Google: # - collection: ^1.17.0 - crypto: ^3.0.3 - ffi: ^2.1.0 - js: ^0.7.1 - meta: ^1.8.0 - typed_data: ^1.3.0 + collection: ^1.19.1 + crypto: ^3.0.6 + ffi: ^2.1.4 + js: ^0.7.2 + meta: ^1.16.0 + typed_data: ^1.4.0 + web: ^1.1.0 dev_dependencies: # # Packages by Google: # - lints: ^2.1.1 - test: ^1.24.0 + lints: ^5.1.1 + test: ^1.25.15 diff --git a/cryptography/test/browser_cryptography_test.dart b/cryptography/test/browser_cryptography_test.dart index 7d2375a..4764fe5 100644 --- a/cryptography/test/browser_cryptography_test.dart +++ b/cryptography/test/browser_cryptography_test.dart @@ -13,6 +13,8 @@ // limitations under the License. @TestOn('chrome') +library; + import 'package:cryptography_plus/cryptography_plus.dart'; import 'package:cryptography_plus/dart.dart'; import 'package:cryptography_plus/src/browser/aes_cbc.dart'; @@ -74,9 +76,7 @@ void main() { ); }); - test( - 'AesCbc.with256bits(..., paddingAlgorithm: somethingElse) is not BrowserAesCbc', - () { + test('AesCbc.with256bits(..., paddingAlgorithm: somethingElse) is not BrowserAesCbc', () { final algorithm = AesCbc.with256bits( macAlgorithm: MacAlgorithm.empty, paddingAlgorithm: PaddingAlgorithm.zero, diff --git a/cryptography_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift b/cryptography_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift index f4af013..7799e39 100644 --- a/cryptography_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/cryptography_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import cryptography_flutter +import cryptography_flutter_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { CryptographyFlutterPlugin.register(with: registry.registrar(forPlugin: "CryptographyFlutterPlugin")) diff --git a/cryptography_flutter/lib/src/background/background_aes_gcm.dart b/cryptography_flutter/lib/src/background/background_aes_gcm.dart index 8840a02..c4fed02 100644 --- a/cryptography_flutter/lib/src/background/background_aes_gcm.dart +++ b/cryptography_flutter/lib/src/background/background_aes_gcm.dart @@ -51,14 +51,11 @@ class BackgroundAesGcm extends AesGcm with BackgroundCipherMixin { required this.secretKeyLength, this.nonceLength = AesGcm.defaultNonceLength, CryptographyChannelPolicy? channelPolicy, - Random? random, - }) : assert(secretKeyLength == 16 || - secretKeyLength == 24 || - secretKeyLength == 32), - channelPolicy = random != null - ? CryptographyChannelPolicy.never - : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), - super.constructor(random: random); + super.random, + }) : assert(secretKeyLength == 16 || secretKeyLength == 24 || secretKeyLength == 32), + channelPolicy = + random != null ? CryptographyChannelPolicy.never : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), + super.constructor(); BackgroundAesGcm.with128bits({ int nonceLength = AesGcm.defaultNonceLength, diff --git a/cryptography_flutter/lib/src/background/background_chacha20.dart b/cryptography_flutter/lib/src/background/background_chacha20.dart index b82c6b5..08daf1a 100644 --- a/cryptography_flutter/lib/src/background/background_chacha20.dart +++ b/cryptography_flutter/lib/src/background/background_chacha20.dart @@ -40,11 +40,10 @@ class BackgroundChacha extends Chacha20 with BackgroundCipherMixin { /// However, this disables the use of [compute]. BackgroundChacha.poly1305Aead({ CryptographyChannelPolicy? channelPolicy, - Random? random, - }) : channelPolicy = random != null - ? CryptographyChannelPolicy.never - : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), - super.constructor(random: random); + super.random, + }) : channelPolicy = + random != null ? CryptographyChannelPolicy.never : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), + super.constructor(); @override MacAlgorithm get macAlgorithm => const DartChacha20Poly1305AeadMacAlgorithm(); diff --git a/cryptography_flutter/lib/src/flutter/flutter_aes_gcm.dart b/cryptography_flutter/lib/src/flutter/flutter_aes_gcm.dart index eb3812e..fa7139e 100644 --- a/cryptography_flutter/lib/src/flutter/flutter_aes_gcm.dart +++ b/cryptography_flutter/lib/src/flutter/flutter_aes_gcm.dart @@ -51,14 +51,14 @@ class FlutterAesGcm extends AesGcm with FlutterCipherMixin { required this.secretKeyLength, CryptographyChannelPolicy? channelPolicy, AesGcm? fallback, - Random? random, + super.random, }) : fallback = fallback ?? BackgroundAesGcm( secretKeyLength: secretKeyLength, random: random, ), channelPolicy = channelPolicy ?? FlutterCipher.defaultChannelPolicy, - super.constructor(random: random); + super.constructor(); /// Constructs Flutter-optimized [AesGcm] which will use 128-bit keys. /// @@ -136,8 +136,7 @@ class FlutterAesGcm extends AesGcm with FlutterCipherMixin { // key size 192 bits. Why? @override bool get isSupportedPlatform => - FlutterCryptography.isPluginPresent && - ((isAndroid && secretKeyLength != 24) || isCupertino); + FlutterCryptography.isPluginPresent && ((isAndroid && secretKeyLength != 24) || isCupertino); @override int get nonceLength => AesGcm.defaultNonceLength; diff --git a/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart b/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart index 4c7540e..17eaf0a 100644 --- a/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart +++ b/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart @@ -47,10 +47,10 @@ class FlutterChacha20 extends Chacha20 with FlutterCipherMixin { FlutterChacha20.poly1305Aead({ Chacha20? fallback, CryptographyChannelPolicy? channelPolicy, - Random? random, + super.random, }) : fallback = fallback ?? BackgroundChacha.poly1305Aead(), channelPolicy = channelPolicy ?? FlutterCipher.defaultChannelPolicy, - super.constructor(random: random); + super.constructor(); @override String get channelCipherName => 'CHACHA20_POLY1305_AEAD'; @@ -59,8 +59,7 @@ class FlutterChacha20 extends Chacha20 with FlutterCipherMixin { // Enable Android when we the following issues are fixed: // * The Android implementation is slow. @override - bool get isSupportedPlatform => - FlutterCryptography.isPluginPresent && (isAndroid || isCupertino); + bool get isSupportedPlatform => FlutterCryptography.isPluginPresent && (isAndroid || isCupertino); @override MacAlgorithm get macAlgorithm => const DartChacha20Poly1305AeadMacAlgorithm(); diff --git a/cryptography_flutter/lib/src/flutter_cryptography.dart b/cryptography_flutter/lib/src/flutter_cryptography.dart index 37e24a5..c9b6bde 100644 --- a/cryptography_flutter/lib/src/flutter_cryptography.dart +++ b/cryptography_flutter/lib/src/flutter_cryptography.dart @@ -14,9 +14,9 @@ import 'dart:math'; +import 'package:cryptography_flutter_plus/src/flutter/flutter_hmac.dart'; import 'package:cryptography_plus/cryptography_plus.dart'; import 'package:cryptography_plus/dart.dart'; -import 'package:cryptography_flutter_plus/src/flutter/flutter_hmac.dart'; import 'package:flutter/foundation.dart'; import '../cryptography_flutter_plus.dart'; @@ -41,20 +41,18 @@ import '_internal.dart'; class FlutterCryptography extends BrowserCryptography { /// Either [FlutterCryptography] or [BrowserCryptography] depending on /// [FlutterCryptography.isPluginPresent]. - static final Cryptography defaultInstance = - kIsWeb ? BrowserCryptography.defaultInstance : FlutterCryptography(); + static final Cryptography defaultInstance = kIsWeb ? BrowserCryptography.defaultInstance : FlutterCryptography(); /// Tells whether the current platform has a plugin. /// /// Only Android, iOS, and Mac OS X are supported at the moment. - static bool get isPluginPresent => - !kIsWeb && !hasSeenMissingPluginException && (isAndroid || isCupertino); + static bool get isPluginPresent => !kIsWeb && !hasSeenMissingPluginException && (isAndroid || isCupertino); Chacha20? _chacha20Poly1305Aead; Ed25519? _ed25519; X25519? _x25519; - FlutterCryptography({Random? random}) : super(random: random); + FlutterCryptography({super.random}); @override AesGcm aesGcm({ @@ -200,8 +198,7 @@ class FlutterCryptography extends BrowserCryptography { } @override - FlutterCryptography withRandom(Random? random) => - FlutterCryptography(random: random); + FlutterCryptography withRandom(Random? random) => FlutterCryptography(random: random); @override X25519 x25519() { diff --git a/cryptography_flutter/pubspec.yaml b/cryptography_flutter/pubspec.yaml index e211585..1f9aaa1 100644 --- a/cryptography_flutter/pubspec.yaml +++ b/cryptography_flutter/pubspec.yaml @@ -28,7 +28,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.3 + flutter_lints: ^5.0.0 dependency_overrides: cryptography_plus: diff --git a/cryptography_flutter_integration_test/macos/Flutter/GeneratedPluginRegistrant.swift b/cryptography_flutter_integration_test/macos/Flutter/GeneratedPluginRegistrant.swift index f4af013..7799e39 100644 --- a/cryptography_flutter_integration_test/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/cryptography_flutter_integration_test/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import cryptography_flutter +import cryptography_flutter_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { CryptographyFlutterPlugin.register(with: registry.registrar(forPlugin: "CryptographyFlutterPlugin")) diff --git a/cryptography_test/pubspec.yaml b/cryptography_test/pubspec.yaml index 43d01a7..14134ae 100644 --- a/cryptography_test/pubspec.yaml +++ b/cryptography_test/pubspec.yaml @@ -17,21 +17,21 @@ dependencies: # # Packages by Google: # - collection: ^1.17.0 - crypto: ^3.0.3 - test: ^1.24.0 - typed_data: ^1.3.0 + collection: ^1.19.1 + crypto: ^3.0.6 + test: ^1.25.15 + typed_data: ^1.4.0 # # Packages by github.com/dint-dev: # - cryptography_plus: ^2.5.1 + cryptography_plus: ^2.7.1 dev_dependencies: # # Packages by Google: # - lints: ^2.1.1 + lints: ^5.1.1 dependency_overrides: cryptography_plus: diff --git a/jwk/pubspec.yaml b/jwk/pubspec.yaml index 547d9b1..3a7fc14 100644 --- a/jwk/pubspec.yaml +++ b/jwk/pubspec.yaml @@ -7,12 +7,12 @@ environment: sdk: ">=3.1.0 <4.0.0" dependencies: - collection: ^1.17.0 + collection: ^1.19.1 cryptography_plus: ^2.7.1 dev_dependencies: - lints: ^2.1.1 - test: ^1.24.0 + lints: ^5.1.1 + test: ^1.25.15 dependency_overrides: cryptography_plus: