From ce7dce5ab8154459d557f418d1eb7b8604b93365 Mon Sep 17 00:00:00 2001 From: terrier989 Date: Wed, 19 Nov 2025 17:45:25 +0000 Subject: [PATCH] Fix analysis warnings and improve CI pipeline --- .github/FUNDING.yml | 2 - .github/workflows/dart.yml | 199 ++++++++++++++++-- .github/workflows/publish_cryptography.yml | 15 ++ .../publish_cryptography_flutter.yml | 15 ++ .github/workflows/publish_jwk.yml | 15 ++ README.md | 2 +- cryptography/dart_test.yaml | 6 +- cryptography/lib/browser.dart | 2 +- cryptography/lib/cryptography.dart | 2 +- cryptography/lib/dart.dart | 2 +- cryptography/lib/helpers.dart | 2 +- .../lib/src/browser/_javascript_bindings.dart | 2 +- cryptography/lib/src/browser/aes_cbc.dart | 4 +- cryptography/lib/src/browser/aes_ctr.dart | 4 +- cryptography/lib/src/browser/aes_gcm.dart | 4 +- .../lib/src/browser/browser_cryptography.dart | 5 +- ...browser_cryptography_when_not_browser.dart | 2 +- cryptography/lib/src/browser/rsa_pss.dart | 6 +- .../lib/src/browser/rsa_ssa_pkcs1v15.dart | 6 +- .../lib/src/cryptography/algorithms.dart | 14 +- cryptography/lib/src/cryptography/cipher.dart | 2 +- .../lib/src/cryptography/cipher_wand.dart | 2 +- .../lib/src/cryptography/ec_key_pair.dart | 5 +- cryptography/lib/src/dart/aes_impl.dart | 6 +- cryptography/lib/src/dart/ed25519.dart | 5 +- cryptography/lib/src/dart/x25519.dart | 3 +- .../test/browser_cryptography_test.dart | 2 + cryptography_flutter/lib/android.dart | 2 +- .../lib/cryptography_flutter.dart | 2 +- .../src/background/background_aes_gcm.dart | 4 +- .../src/background/background_chacha20.dart | 4 +- .../lib/src/flutter/flutter_aes_gcm.dart | 4 +- .../lib/src/flutter/flutter_chacha20.dart | 4 +- .../lib/src/flutter_cryptography.dart | 2 +- .../.gitignore | 2 + .../analysis_options.yaml | 30 +-- .../android/app/build.gradle | 2 +- .../android/build.gradle | 4 +- .../macos/Podfile | 2 +- .../macos/Runner.xcodeproj/project.pbxproj | 8 +- .../xcshareddata/xcschemes/Runner.xcscheme | 3 +- .../macos/Runner/AppDelegate.swift | 6 +- cryptography_test/dart_test.yaml | 6 +- cryptography_test/lib/cipher.dart | 2 +- cryptography_test/lib/cryptography_test.dart | 2 +- cryptography_test/lib/hash.dart | 2 +- cryptography_test/lib/hex.dart | 2 +- cryptography_test/lib/key_exchange.dart | 2 +- cryptography_test/lib/signature.dart | 2 +- jwk/dart_test.yaml | 6 +- jwk/example/example.dart | 18 ++ jwk/lib/jwk.dart | 2 +- 52 files changed, 333 insertions(+), 124 deletions(-) delete mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/publish_cryptography.yml create mode 100644 .github/workflows/publish_cryptography_flutter.yml create mode 100644 .github/workflows/publish_jwk.yml create mode 100644 jwk/example/example.dart diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index b1c2f8ec..00000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: [terrier989] -open_collective: [cryptography] \ No newline at end of file diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index d206db3d..6dfdbf73 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,31 +1,190 @@ name: Dart CI -on: [push, pull_request] +env: + PANA_SCORE_THRESHOLD: 40 + +on: + push: + branches: + - master + pull_request: + schedule: + - cron: '0 0 1 * *' # Monthly run on the first day of the month at 00:00 UTC jobs: - test: - runs-on: ${{ matrix.os }} + + # + # Dart packages: format and analyze + # + dart_analyze: + name: "Analyze" + runs-on: ubuntu-slim strategy: + fail-fast: false matrix: - os: [ubuntu-latest] - sdk: [stable, beta, dev] + package: + - cryptography + - jwk + sdk: + # The oldest supported Dart SDK at the moment. + # Feel free to bump it up whenever needed. + - 3.3.0 + + # We want to support the latest beta SDK as well. + - beta steps: - - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 with: sdk: ${{ matrix.sdk }} - - name: Run tests (cryptography) - run: dart test --platform vm - working-directory: ./cryptography - - name: Run tests (cryptography_test) - run: dart test --platform vm - working-directory: ./cryptography_test - - name: Run tests (jwk) - run: dart test --platform vm - working-directory: ./jwk - - name: Analyze (cryptography) - run: dart analyze - working-directory: ./cryptography - - name: Analyze (jwk) + - uses: actions/checkout@v3 + - name: Get dependencies + run: dart pub get + working-directory: ./${{ matrix.package }} + - name: Verify that code is formatted + continue-on-error: true + run: dart format --set-exit-if-changed . + working-directory: "./${{ matrix.package }}" + - name: Analyze run: dart analyze - working-directory: ./jwk \ No newline at end of file + working-directory: ./${{ matrix.package }} + + # + # Dart packages: test + # + dart_test: + name: "Test" + needs: dart_analyze + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: + - cryptography + - jwk + compiler: + - vm + - dart2js + steps: + - uses: browser-actions/setup-chrome@v2 + if: ${{ matrix.compiler != 'vm' }} + - uses: dart-lang/setup-dart@v1 + with: + sdk: beta + - uses: actions/checkout@v3 + - name: Get dependencies + run: dart pub get + working-directory: ./${{ matrix.package }} + - name: "Test: VM build" + if: ${{ matrix.compiler == 'vm' }} + run: dart test --platform vm + working-directory: ./${{ matrix.package }} + - name: "Test: JS build" + if: ${{ matrix.compiler == 'vm' }} + run: dart test --platform chrome --compiler dart2js + working-directory: ./${{ matrix.package }} + + # + # Dart packages: PANA score + # + dart_package_health: + name: "PANA" + needs: dart_analyze + runs-on: ubuntu-slim + strategy: + fail-fast: false + matrix: + package: + - cryptography + - jwk + steps: + - uses: dart-lang/setup-dart@v1 + - uses: actions/checkout@v3 + - name: Get dependencies + run: dart pub get + working-directory: ./${{ matrix.package }} + - name: Print outdated dependencies + continue-on-error: true + run: dart pub outdated + working-directory: ./${{ matrix.package }} + - name: Install package analyzer + run: dart pub global activate pana + - name: Run package analyzer + continue-on-error: true + run: dart pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD . + working-directory: ./${{ matrix.package }} + # + # Flutter packages: format and analyze + # + flutter_analyze: + name: "Analyze" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: + - cryptography_flutter + - cryptography_flutter_integration_test + sdk: + # The oldest supported Dart SDK at the moment. + # Feel free to bump it up whenever needed. + - 3.35.0 + + # We want to support the latest beta SDK as well. + - beta + steps: + - name: Install Flutter + run: | + cd $HOME + git clone https://github.com/flutter/flutter.git --depth 1 -b ${{ matrix.sdk }} _flutter + echo "$HOME/_flutter/bin" >> $GITHUB_PATH + cd $GITHUB_WORKSPACE + - uses: actions/checkout@v3 + - name: Get dependencies + run: flutter pub get + working-directory: ./${{ matrix.package }} + - name: Verify that code is formatted + continue-on-error: true + run: dart format --set-exit-if-changed . + working-directory: ./${{ matrix.package }} + - name: Analyze + run: flutter analyze + working-directory: ./${{ matrix.package }} + + # + # Unfortunately we don't have Flutter integration tests in Github Actions yet. :( + # + + # + # Flutter packages: PANA score + # + flutter_package_health: + name: "PANA" + needs: flutter_analyze + strategy: + fail-fast: false + matrix: + package: + - cryptography_flutter + runs-on: ubuntu-latest + steps: + - name: Install Flutter + run: | + cd $HOME + git clone https://github.com/flutter/flutter.git --depth 1 -b beta _flutter + echo "$HOME/_flutter/bin" >> $GITHUB_PATH + cd $GITHUB_WORKSPACE + - uses: actions/checkout@v3 + - name: Get dependencies + run: flutter pub get + working-directory: ./${{ matrix.package }} + - name: Print outdated dependencies + continue-on-error: true + run: flutter pub outdated + working-directory: ./${{ matrix.package }} + - name: Install package analyzer + run: flutter pub global activate pana + working-directory: ./${{ matrix.package }} + - name: Run package analyzer + continue-on-error: true + run: flutter pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD . + working-directory: ./${{ matrix.package }} \ No newline at end of file diff --git a/.github/workflows/publish_cryptography.yml b/.github/workflows/publish_cryptography.yml new file mode 100644 index 00000000..d0832b97 --- /dev/null +++ b/.github/workflows/publish_cryptography.yml @@ -0,0 +1,15 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'cryptography-v[0-9]+.[0-9]+.[0-9]+' + +jobs: + publish: + permissions: + id-token: write + uses: dart-lang/setup-dart/.github/workflows/publish.yml@daef289245bc5d4ab7864e0788a58108a9be6c99 + with: + environment: pub.dev + working-directory: ./cryptography \ No newline at end of file diff --git a/.github/workflows/publish_cryptography_flutter.yml b/.github/workflows/publish_cryptography_flutter.yml new file mode 100644 index 00000000..897fcec6 --- /dev/null +++ b/.github/workflows/publish_cryptography_flutter.yml @@ -0,0 +1,15 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'cryptography_flutter-v[0-9]+.[0-9]+.[0-9]+' + +jobs: + publish: + permissions: + id-token: write + uses: dart-lang/setup-dart/.github/workflows/publish.yml@daef289245bc5d4ab7864e0788a58108a9be6c99 + with: + environment: pub.dev + working-directory: ./cryptography_flutter \ No newline at end of file diff --git a/.github/workflows/publish_jwk.yml b/.github/workflows/publish_jwk.yml new file mode 100644 index 00000000..c515e33c --- /dev/null +++ b/.github/workflows/publish_jwk.yml @@ -0,0 +1,15 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'jwk-v[0-9]+.[0-9]+.[0-9]+' + +jobs: + publish: + permissions: + id-token: write + uses: dart-lang/setup-dart/.github/workflows/publish.yml@daef289245bc5d4ab7864e0788a58108a9be6c99 + with: + environment: pub.dev + working-directory: ./jwk \ No newline at end of file diff --git a/README.md b/README.md index ce8bf49b..fc8ca2df 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Cryptographic packages for [Dart](https://dart.dev) / [Flutter](https://flutter.dev) developers. Open-sourced under the [Apache License 2.0](LICENSE). -Maintained by [gohilla.com](https://gohilla.com). Licensed under the [Apache License 2.0](LICENSE). +Maintained by [terrier989](https://github.com/terrier989). Licensed under the [Apache License 2.0](LICENSE). ## Packages * [cryptography](cryptography) diff --git a/cryptography/dart_test.yaml b/cryptography/dart_test.yaml index 6b9a6374..cbaa1310 100644 --- a/cryptography/dart_test.yaml +++ b/cryptography/dart_test.yaml @@ -1 +1,5 @@ -platforms: [ vm, chrome ] \ No newline at end of file +platforms: + - vm + - chrome +compilers: + - dart2js \ No newline at end of file diff --git a/cryptography/lib/browser.dart b/cryptography/lib/browser.dart index bf28041b..f578cce7 100644 --- a/cryptography/lib/browser.dart +++ b/cryptography/lib/browser.dart @@ -17,7 +17,7 @@ 'This library will be removed in a future major version.' ' You can find `BrowserCryptography` class in "package:cryptography/cryptography.dart".', ) -library cryptography.browser; +library; export 'src/browser/browser_cryptography_when_not_browser.dart' if (dart.library.html) 'src/browser/browser_cryptography.dart'; diff --git a/cryptography/lib/cryptography.dart b/cryptography/lib/cryptography.dart index 0bbcdbc0..1a84609a 100644 --- a/cryptography/lib/cryptography.dart +++ b/cryptography/lib/cryptography.dart @@ -24,7 +24,7 @@ /// /// ## Factory methods /// [Cryptography] contains factory methods for cryptographic algorithms. -library cryptography; +library; import 'package:cryptography/cryptography.dart'; diff --git a/cryptography/lib/dart.dart b/cryptography/lib/dart.dart index 51d93474..9c2cfe56 100644 --- a/cryptography/lib/dart.dart +++ b/cryptography/lib/dart.dart @@ -15,7 +15,7 @@ /// Cryptographic algorithms implemented in pure Dart. /// /// See [DartCryptography]. -library cryptography.dart; +library; import 'package:cryptography/dart.dart'; diff --git a/cryptography/lib/helpers.dart b/cryptography/lib/helpers.dart index 8680c053..b79707f3 100644 --- a/cryptography/lib/helpers.dart +++ b/cryptography/lib/helpers.dart @@ -13,7 +13,7 @@ // limitations under the License. /// Various helpers for cryptography. -library cryptography.helpers; +library; export 'src/helpers/constant_time_equality.dart'; export 'src/helpers/delegating_classes.dart'; diff --git a/cryptography/lib/src/browser/_javascript_bindings.dart b/cryptography/lib/src/browser/_javascript_bindings.dart index 7d83ab39..b8d40d42 100644 --- a/cryptography/lib/src/browser/_javascript_bindings.dart +++ b/cryptography/lib/src/browser/_javascript_bindings.dart @@ -13,7 +13,7 @@ // limitations under the License. @JS() -library web_crypto_api; +library; import 'dart:convert' show base64Url; import 'dart:html' show CryptoKey; diff --git a/cryptography/lib/src/browser/aes_cbc.dart b/cryptography/lib/src/browser/aes_cbc.dart index 93036585..c2ec8313 100644 --- a/cryptography/lib/src/browser/aes_cbc.dart +++ b/cryptography/lib/src/browser/aes_cbc.dart @@ -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 2594bdfc..bfe49e0f 100644 --- a/cryptography/lib/src/browser/aes_ctr.dart +++ b/cryptography/lib/src/browser/aes_ctr.dart @@ -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 6381a093..3f9851ed 100644 --- a/cryptography/lib/src/browser/aes_gcm.dart +++ b/cryptography/lib/src/browser/aes_gcm.dart @@ -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 bfb1a0a7..0ff67428 100644 --- a/cryptography/lib/src/browser/browser_cryptography.dart +++ b/cryptography/lib/src/browser/browser_cryptography.dart @@ -48,9 +48,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({ 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 66ae3303..56fb6d29 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 9cf2e5eb..54bed940 100644 --- a/cryptography/lib/src/browser/rsa_pss.dart +++ b/cryptography/lib/src/browser/rsa_pss.dart @@ -272,7 +272,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 6e4d005f..87141224 100644 --- a/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart +++ b/cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart @@ -209,9 +209,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 697d9b94..c862a662 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({ @@ -368,7 +368,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, @@ -878,7 +878,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 @@ -2107,7 +2107,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 +2231,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. /// diff --git a/cryptography/lib/src/cryptography/cipher.dart b/cryptography/lib/src/cryptography/cipher.dart index bcb349de..1f6e8337 100644 --- a/cryptography/lib/src/cryptography/cipher.dart +++ b/cryptography/lib/src/cryptography/cipher.dart @@ -399,7 +399,7 @@ abstract class Cipher { String clearText, { required SecretKey secretKey, }) async { - final bytes = utf8.encode(clearText) as Uint8List; + final bytes = utf8.encode(clearText); final secretBox = await encrypt( bytes, secretKey: secretKey, diff --git a/cryptography/lib/src/cryptography/cipher_wand.dart b/cryptography/lib/src/cryptography/cipher_wand.dart index 48002eb6..e927eb87 100644 --- a/cryptography/lib/src/cryptography/cipher_wand.dart +++ b/cryptography/lib/src/cryptography/cipher_wand.dart @@ -177,7 +177,7 @@ abstract class CipherWand extends Wand { /// } /// ``` Future encryptString(String clearText) async { - final bytes = utf8.encode(clearText) as Uint8List; + final bytes = utf8.encode(clearText); final secretBox = await encrypt( bytes, possibleBuffer: bytes, diff --git a/cryptography/lib/src/cryptography/ec_key_pair.dart b/cryptography/lib/src/cryptography/ec_key_pair.dart index 847d21ec..1ac7bd24 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 { diff --git a/cryptography/lib/src/dart/aes_impl.dart b/cryptography/lib/src/dart/aes_impl.dart index 8b25d196..f9b8d864 100644 --- a/cryptography/lib/src/dart/aes_impl.dart +++ b/cryptography/lib/src/dart/aes_impl.dart @@ -356,9 +356,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 ef055e66..23699661 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/cryptography.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 e7cfbd55..7b7175ea 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/cryptography.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; diff --git a/cryptography/test/browser_cryptography_test.dart b/cryptography/test/browser_cryptography_test.dart index cb9ce06f..d08550f1 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/cryptography.dart'; import 'package:cryptography/dart.dart'; import 'package:cryptography/src/browser/aes_cbc.dart'; diff --git a/cryptography_flutter/lib/android.dart b/cryptography_flutter/lib/android.dart index eef98840..4b7d0c6c 100644 --- a/cryptography_flutter/lib/android.dart +++ b/cryptography_flutter/lib/android.dart @@ -1,5 +1,5 @@ /// Helpers for Android. -library cryptography_flutter.android; +library; import 'package:flutter/services.dart'; diff --git a/cryptography_flutter/lib/cryptography_flutter.dart b/cryptography_flutter/lib/cryptography_flutter.dart index ba3e1f52..76ddfb9f 100644 --- a/cryptography_flutter/lib/cryptography_flutter.dart +++ b/cryptography_flutter/lib/cryptography_flutter.dart @@ -15,7 +15,7 @@ /// An optimized version of [package:cryptography](https://pub.dev/packages/cryptography). /// /// See [FlutterCryptography] for usage instructions. -library cryptography_flutter; +library; import 'package:cryptography_flutter/cryptography_flutter.dart'; diff --git a/cryptography_flutter/lib/src/background/background_aes_gcm.dart b/cryptography_flutter/lib/src/background/background_aes_gcm.dart index 1f2642a4..7d7b5f21 100644 --- a/cryptography_flutter/lib/src/background/background_aes_gcm.dart +++ b/cryptography_flutter/lib/src/background/background_aes_gcm.dart @@ -51,14 +51,14 @@ class BackgroundAesGcm extends AesGcm with BackgroundCipherMixin { required this.secretKeyLength, this.nonceLength = AesGcm.defaultNonceLength, CryptographyChannelPolicy? channelPolicy, - Random? random, + super.random, }) : assert(secretKeyLength == 16 || secretKeyLength == 24 || secretKeyLength == 32), channelPolicy = random != null ? CryptographyChannelPolicy.never : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), - super.constructor(random: random); + 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 ce8c0e87..2c490ff8 100644 --- a/cryptography_flutter/lib/src/background/background_chacha20.dart +++ b/cryptography_flutter/lib/src/background/background_chacha20.dart @@ -40,11 +40,11 @@ class BackgroundChacha extends Chacha20 with BackgroundCipherMixin { /// However, this disables the use of [compute]. BackgroundChacha.poly1305Aead({ CryptographyChannelPolicy? channelPolicy, - Random? random, + super.random, }) : channelPolicy = random != null ? CryptographyChannelPolicy.never : (channelPolicy ?? BackgroundCipher.defaultChannelPolicy), - super.constructor(random: random); + 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 4780d525..1df5dd49 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. /// diff --git a/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart b/cryptography_flutter/lib/src/flutter/flutter_chacha20.dart index a906136c..3fa44c97 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'; diff --git a/cryptography_flutter/lib/src/flutter_cryptography.dart b/cryptography_flutter/lib/src/flutter_cryptography.dart index 61887878..3d66748c 100644 --- a/cryptography_flutter/lib/src/flutter_cryptography.dart +++ b/cryptography_flutter/lib/src/flutter_cryptography.dart @@ -54,7 +54,7 @@ class FlutterCryptography extends BrowserCryptography { Ed25519? _ed25519; X25519? _x25519; - FlutterCryptography({Random? random}) : super(random: random); + FlutterCryptography({super.random}); @override AesGcm aesGcm({ diff --git a/cryptography_flutter_integration_test/.gitignore b/cryptography_flutter_integration_test/.gitignore index 24476c5d..6c319542 100644 --- a/cryptography_flutter_integration_test/.gitignore +++ b/cryptography_flutter_integration_test/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/cryptography_flutter_integration_test/analysis_options.yaml b/cryptography_flutter_integration_test/analysis_options.yaml index 61b6c4de..a3be6b82 100644 --- a/cryptography_flutter_integration_test/analysis_options.yaml +++ b/cryptography_flutter_integration_test/analysis_options.yaml @@ -1,29 +1 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. - -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/cryptography_flutter_integration_test/android/app/build.gradle b/cryptography_flutter_integration_test/android/app/build.gradle index 780ec638..691a9b8d 100644 --- a/cryptography_flutter_integration_test/android/app/build.gradle +++ b/cryptography_flutter_integration_test/android/app/build.gradle @@ -47,7 +47,7 @@ android { applicationId "com.example.cryptography_flutter_integration_test" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion 21 + minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/cryptography_flutter_integration_test/android/build.gradle b/cryptography_flutter_integration_test/android/build.gradle index 58a8c74b..cc1d40fd 100644 --- a/cryptography_flutter_integration_test/android/build.gradle +++ b/cryptography_flutter_integration_test/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register("clean", Delete) { + delete rootProject.layout.buildDirectory } diff --git a/cryptography_flutter_integration_test/macos/Podfile b/cryptography_flutter_integration_test/macos/Podfile index 049abe29..9ec46f8c 100644 --- a/cryptography_flutter_integration_test/macos/Podfile +++ b/cryptography_flutter_integration_test/macos/Podfile @@ -1,4 +1,4 @@ -platform :osx, '10.14' +platform :osx, '10.15' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/cryptography_flutter_integration_test/macos/Runner.xcodeproj/project.pbxproj b/cryptography_flutter_integration_test/macos/Runner.xcodeproj/project.pbxproj index 850a9dbc..ef4de5f3 100644 --- a/cryptography_flutter_integration_test/macos/Runner.xcodeproj/project.pbxproj +++ b/cryptography_flutter_integration_test/macos/Runner.xcodeproj/project.pbxproj @@ -203,7 +203,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { @@ -405,7 +405,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -484,7 +484,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -531,7 +531,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/cryptography_flutter_integration_test/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/cryptography_flutter_integration_test/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 22f63cb5..733168f4 100644 --- a/cryptography_flutter_integration_test/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/cryptography_flutter_integration_test/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ diff --git a/cryptography_flutter_integration_test/macos/Runner/AppDelegate.swift b/cryptography_flutter_integration_test/macos/Runner/AppDelegate.swift index d53ef643..b3c17614 100644 --- a/cryptography_flutter_integration_test/macos/Runner/AppDelegate.swift +++ b/cryptography_flutter_integration_test/macos/Runner/AppDelegate.swift @@ -1,9 +1,13 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/cryptography_test/dart_test.yaml b/cryptography_test/dart_test.yaml index 6b9a6374..cbaa1310 100644 --- a/cryptography_test/dart_test.yaml +++ b/cryptography_test/dart_test.yaml @@ -1 +1,5 @@ -platforms: [ vm, chrome ] \ No newline at end of file +platforms: + - vm + - chrome +compilers: + - dart2js \ No newline at end of file diff --git a/cryptography_test/lib/cipher.dart b/cryptography_test/lib/cipher.dart index 5dbcf2b6..7ca43cc7 100644 --- a/cryptography_test/lib/cipher.dart +++ b/cryptography_test/lib/cipher.dart @@ -16,7 +16,7 @@ /// /// ## Example /// See [testCipher]. -library cryptography_test.cipher; +library; import 'dart:typed_data'; diff --git a/cryptography_test/lib/cryptography_test.dart b/cryptography_test/lib/cryptography_test.dart index d3823a02..d440ec30 100644 --- a/cryptography_test/lib/cryptography_test.dart +++ b/cryptography_test/lib/cryptography_test.dart @@ -31,7 +31,7 @@ /// testCryptography(); /// } /// ``` -library cryptography_test; +library; import 'package:cryptography/cryptography.dart'; import 'package:cryptography_test/algorithms/argon2.dart'; diff --git a/cryptography_test/lib/hash.dart b/cryptography_test/lib/hash.dart index 86beb997..4c973b24 100644 --- a/cryptography_test/lib/hash.dart +++ b/cryptography_test/lib/hash.dart @@ -16,7 +16,7 @@ /// /// ## Example /// See [testHashAlgorithm]. -library cryptography_test.hash_algorithm; +library; import 'dart:async'; import 'dart:typed_data'; diff --git a/cryptography_test/lib/hex.dart b/cryptography_test/lib/hex.dart index 7c684e40..06f44405 100644 --- a/cryptography_test/lib/hex.dart +++ b/cryptography_test/lib/hex.dart @@ -31,7 +31,7 @@ /// testCryptography(); /// } /// ``` -library cryptography_test.hex; +library; import 'dart:typed_data'; diff --git a/cryptography_test/lib/key_exchange.dart b/cryptography_test/lib/key_exchange.dart index 665c62ff..8870399c 100644 --- a/cryptography_test/lib/key_exchange.dart +++ b/cryptography_test/lib/key_exchange.dart @@ -16,7 +16,7 @@ /// /// ## Example /// See [testKeyExchangeAlgorithm]. -library cryptography_test.key_exchange_algorithm; +library; import 'package:cryptography/cryptography.dart'; import 'package:cryptography/dart.dart'; diff --git a/cryptography_test/lib/signature.dart b/cryptography_test/lib/signature.dart index 4db7f41e..6b5e66a8 100644 --- a/cryptography_test/lib/signature.dart +++ b/cryptography_test/lib/signature.dart @@ -16,7 +16,7 @@ /// /// ## Example /// See [testSignatureAlgorithm]. -library cryptography_test.signature_algorithm; +library; import 'dart:typed_data'; diff --git a/jwk/dart_test.yaml b/jwk/dart_test.yaml index 6b9a6374..cbaa1310 100644 --- a/jwk/dart_test.yaml +++ b/jwk/dart_test.yaml @@ -1 +1,5 @@ -platforms: [ vm, chrome ] \ No newline at end of file +platforms: + - vm + - chrome +compilers: + - dart2js \ No newline at end of file diff --git a/jwk/example/example.dart b/jwk/example/example.dart new file mode 100644 index 00000000..b6917da5 --- /dev/null +++ b/jwk/example/example.dart @@ -0,0 +1,18 @@ +import 'package:jwk/jwk.dart'; + +void main() { + final jwk = Jwk.fromJson({ + 'kty': 'RSA', + 'n': '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86' + 'E3K3zV9zzTtmCGR2DhKNuNSZp2dHfvGZ1WLdqt4yW8c5C4OAI8kPpG6VfT1GXvQ' + 'r2Xi0VH6hM0axqaz0alG5jFT8H4qerLz6QvUOSgf3LT6rdzjvXSKyUsF86RLWvu' + 'oXFQrXeGsy3O3px4hi2TGMHhzwQK1YkYp6fEnY/zYI25G4b8iKXg2sr1m9T25Z4' + 'eOVBzEoU3pmMxMqYz1K0p0xX4mjU7vsfgQCIp9Zc3T8f7vfxn9pkOe7wOZyNxL' + 'g', + 'e': 'AQAB', + 'alg': 'RS256', + }); + print('kty: ${jwk.kty}'); + print('n: ${jwk.n}'); + print('e: ${jwk.e}'); +} diff --git a/jwk/lib/jwk.dart b/jwk/lib/jwk.dart index b2f69811..ca7ca048 100644 --- a/jwk/lib/jwk.dart +++ b/jwk/lib/jwk.dart @@ -15,7 +15,7 @@ /// JWK (JSON Web Key) encoding and decoding. /// /// See documentation for the class [Jwk]. -library jwk; +library; import 'dart:convert'; import 'dart:typed_data';