From 586d2960fb52aedf9f69a75b6759f631f2087c00 Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Thu, 2 Dec 2021 12:10:19 +0100 Subject: [PATCH 1/6] Migrated to null safety --- example/pubspec.lock | 10 ++++----- lib/virgil_e3kit.dart | 48 +++++++++++++++++++++---------------------- pubspec.lock | 12 +++++------ pubspec.yaml | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index e879444..1dbe635 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -87,7 +87,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -113,7 +113,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -148,7 +148,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.2" typed_data: dependency: transitive description: diff --git a/lib/virgil_e3kit.dart b/lib/virgil_e3kit.dart index 60e02c6..1f09b8e 100644 --- a/lib/virgil_e3kit.dart +++ b/lib/virgil_e3kit.dart @@ -15,10 +15,10 @@ class Ethree { this._channel.setMethodCallHandler(this.handleMethodCall); } - static Future init( + static Future init( String identity, GetJWTCallback tokenCallback) async { final String channelID = getRandString(32); - bool result = await globalChannel + bool? result = await globalChannel .invokeMethod('init', {'channelID': channelID, 'identity': identity}); if (result == false) { return null; @@ -30,84 +30,84 @@ class Ethree { return ethree; } - Future getIdentity() async { + Future getIdentity() async { return _channel.invokeMethod('getIdentity'); } - Future register() async { + Future register() async { return _channel.invokeMethod('register'); } - Future unregister() async { + Future unregister() async { return _channel.invokeMethod("unregister"); } - Future backupPrivateKey(String password) async { + Future backupPrivateKey(String password) async { return _channel.invokeMethod("backupPrivateKey", {"password": password}); } - Future changePassword(String oldPassword, String newPassword) async { + Future changePassword(String oldPassword, String newPassword) async { return _channel.invokeMethod("changePassword", {"oldPassword": oldPassword, "newPassword": newPassword}); } - Future resetPrivateKeyBackup() async { + Future resetPrivateKeyBackup() async { return _channel.invokeMethod("resetPrivateKeyBackup"); } - Future restorePrivateKey(String password) async { + Future restorePrivateKey(String password) async { return _channel.invokeMethod("restorePrivateKey", {'password': password}); } - Future rotatePrivateKey() async { + Future rotatePrivateKey() async { return _channel.invokeMethod("rotatePrivateKey"); } - Future hasLocalPrivateKey() async { + Future hasLocalPrivateKey() async { return _channel.invokeMethod("hasLocalPrivateKey"); } - Future cleanup() async { + Future cleanup() async { return _channel.invokeMethod("cleanup"); } - Future findUser(String identity) async { - final String card = + Future findUser(String identity) async { + final String? card = await _channel.invokeMethod('findUser', {'identity': identity}); return card; } - Future findUsers(List identities, bool forceReload) async { - Map users = await _channel.invokeMethod( + Future findUsers(List identities, bool forceReload) async { + Map? users = await _channel.invokeMethod( "findUsers", {"identities": identities, "forceReload": forceReload}); return users; } - Future findCachedUser(String identity) async { - final String card = + Future findCachedUser(String identity) async { + final String? card = await _channel.invokeMethod("findCachedUser", {'identity': identity}); return card; } - Future findCachedUsers(List identities) async { - final Map users = await _channel + Future findCachedUsers(List identities) async { + final Map? users = await _channel .invokeMethod("findCachedUsers", {"identities": identities}); return users; } - Future updateCachedUsers() async { + Future updateCachedUsers() async { return _channel.invokeMethod("updateCachedUsers"); } - Future authEncrypt(Map users, String data) async { + Future authEncrypt(Map users, String data) async { return _channel.invokeMethod("authEncrypt", {"users": users, "data": data}); } - Future authDecrypt(String data, [String card = ""]) async { + Future authDecrypt(String data, [String card = ""]) async { return _channel.invokeMethod("authDecrypt", {"data": data, "card": card}); } @@ -116,7 +116,7 @@ class Ethree { case 'tokenCallback': return this.tokenCallback(); } - return null; + return Future.error("Unknown method ${call.method}"); } } diff --git a/pubspec.lock b/pubspec.lock index ef01c9f..4935c14 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -73,7 +73,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -92,7 +92,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -127,7 +127,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.2" typed_data: dependency: transitive description: @@ -143,5 +143,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3b6c521..d6f887c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://virgilsecurity.com repository: https://github.com/VirgilSecurity/virgil-e3kit-flutter environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.20.0" dependencies: From 59be6ea20f12954055b2f46b6d45fcfd46b298d0 Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Tue, 7 Dec 2021 09:29:11 +0100 Subject: [PATCH 2/6] Updated handleMethodCall to private --- lib/virgil_e3kit.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/virgil_e3kit.dart b/lib/virgil_e3kit.dart index 1f09b8e..6f97e1b 100644 --- a/lib/virgil_e3kit.dart +++ b/lib/virgil_e3kit.dart @@ -12,7 +12,7 @@ class Ethree { final String identity; Ethree(this.identity, this.tokenCallback, this._channel) { - this._channel.setMethodCallHandler(this.handleMethodCall); + this._channel.setMethodCallHandler(this._handleMethodCall); } static Future init( @@ -111,7 +111,7 @@ class Ethree { return _channel.invokeMethod("authDecrypt", {"data": data, "card": card}); } - Future handleMethodCall(MethodCall call) { + Future _handleMethodCall(MethodCall call) { switch (call.method) { case 'tokenCallback': return this.tokenCallback(); From 2507e5ef5b591f6d0026b66bcbcd070e19504746 Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Tue, 7 Dec 2021 09:30:30 +0100 Subject: [PATCH 3/6] Removed unused async keywords --- lib/virgil_e3kit.dart | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/virgil_e3kit.dart b/lib/virgil_e3kit.dart index 6f97e1b..ee8f593 100644 --- a/lib/virgil_e3kit.dart +++ b/lib/virgil_e3kit.dart @@ -30,44 +30,44 @@ class Ethree { return ethree; } - Future getIdentity() async { + Future getIdentity() { return _channel.invokeMethod('getIdentity'); } - Future register() async { + Future register() { return _channel.invokeMethod('register'); } - Future unregister() async { + Future unregister() { return _channel.invokeMethod("unregister"); } - Future backupPrivateKey(String password) async { + Future backupPrivateKey(String password) { return _channel.invokeMethod("backupPrivateKey", {"password": password}); } - Future changePassword(String oldPassword, String newPassword) async { + Future changePassword(String oldPassword, String newPassword) { return _channel.invokeMethod("changePassword", {"oldPassword": oldPassword, "newPassword": newPassword}); } - Future resetPrivateKeyBackup() async { + Future resetPrivateKeyBackup() { return _channel.invokeMethod("resetPrivateKeyBackup"); } - Future restorePrivateKey(String password) async { + Future restorePrivateKey(String password) { return _channel.invokeMethod("restorePrivateKey", {'password': password}); } - Future rotatePrivateKey() async { + Future rotatePrivateKey() { return _channel.invokeMethod("rotatePrivateKey"); } - Future hasLocalPrivateKey() async { + Future hasLocalPrivateKey() { return _channel.invokeMethod("hasLocalPrivateKey"); } - Future cleanup() async { + Future cleanup() { return _channel.invokeMethod("cleanup"); } @@ -99,15 +99,15 @@ class Ethree { return users; } - Future updateCachedUsers() async { + Future updateCachedUsers() { return _channel.invokeMethod("updateCachedUsers"); } - Future authEncrypt(Map users, String data) async { + Future authEncrypt(Map users, String data) { return _channel.invokeMethod("authEncrypt", {"users": users, "data": data}); } - Future authDecrypt(String data, [String card = ""]) async { + Future authDecrypt(String data, [String card = ""]) { return _channel.invokeMethod("authDecrypt", {"data": data, "card": card}); } From b71425101d1f9fd7805ef269890017ccaa28cce0 Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Tue, 7 Dec 2021 09:34:43 +0100 Subject: [PATCH 4/6] Added analysis_options file --- analysis_options.yaml | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..0fee74b --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,86 @@ +analyzer: + strong-mode: + implicit-casts: false + implicit-dynamic: false + errors: + missing_required_param: error + missing_return: error + todo: warning + include_file_not_found: ignore + exclude: + # ignore warnings in files from json_serializable, built_value and most generators. + - "**/*.g.dart" + # ignore warnings in files generated by Freezed specifically. + - "**/*.freezed.dart" + # ignore warnings in files generated for localization. + - "**/generated/**/*.dart" +linter: + rules: + - annotate_overrides + - avoid_empty_else + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_types_as_parameter_names + - avoid_unused_constructor_parameters + - await_only_futures + - camel_case_types + - cancel_subscriptions + - comment_references + - constant_identifier_names + - control_flow_in_finally + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - hash_and_equals + - implementation_imports + - invariant_booleans + - iterable_contains_unrelated_type + - library_names + - library_prefixes + - list_remove_unrelated_type + - no_adjacent_strings_in_list + - no_duplicate_case_values + - non_constant_identifier_names + - null_closures + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_contains + - prefer_equal_for_default_values + - prefer_final_fields + - prefer_initializing_formals + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_single_quotes + - prefer_typing_uninitialized_variables + - recursive_getters + - require_trailing_commas + - slash_for_doc_comments + - test_types_in_equals + - throw_in_finally + - type_init_formals + - unawaited_futures + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_statements + - unnecessary_this + - unrelated_type_equality_checks + - use_rethrow_when_possible + - valid_regexps \ No newline at end of file From d284bcf68478dd8c403550c3c9dc7f313617b88d Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Tue, 7 Dec 2021 09:34:57 +0100 Subject: [PATCH 5/6] Fixed analysis errors and warnings --- lib/virgil_e3kit.dart | 73 +++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/virgil_e3kit.dart b/lib/virgil_e3kit.dart index ee8f593..890c197 100644 --- a/lib/virgil_e3kit.dart +++ b/lib/virgil_e3kit.dart @@ -1,10 +1,12 @@ import 'dart:async'; -import 'dart:math'; import 'dart:convert'; +import 'dart:math'; + import 'package:flutter/services.dart'; typedef GetJWTCallback = Future Function(); -final MethodChannel globalChannel = MethodChannel('com.virgilsecurity/ethree'); +final MethodChannel globalChannel = + const MethodChannel('com.virgilsecurity/ethree'); class Ethree { final MethodChannel _channel; @@ -12,11 +14,13 @@ class Ethree { final String identity; Ethree(this.identity, this.tokenCallback, this._channel) { - this._channel.setMethodCallHandler(this._handleMethodCall); + _channel.setMethodCallHandler(_handleMethodCall); } static Future init( - String identity, GetJWTCallback tokenCallback) async { + String identity, + GetJWTCallback tokenCallback, + ) async { final String channelID = getRandString(32); bool? result = await globalChannel .invokeMethod('init', {'channelID': channelID, 'identity': identity}); @@ -39,84 +43,99 @@ class Ethree { } Future unregister() { - return _channel.invokeMethod("unregister"); + return _channel.invokeMethod('unregister'); } Future backupPrivateKey(String password) { - return _channel.invokeMethod("backupPrivateKey", {"password": password}); + return _channel.invokeMethod('backupPrivateKey', {'password': password}); } Future changePassword(String oldPassword, String newPassword) { - return _channel.invokeMethod("changePassword", - {"oldPassword": oldPassword, "newPassword": newPassword}); + return _channel.invokeMethod('changePassword', { + 'oldPassword': oldPassword, + 'newPassword': newPassword, + }); } Future resetPrivateKeyBackup() { - return _channel.invokeMethod("resetPrivateKeyBackup"); + return _channel.invokeMethod('resetPrivateKeyBackup'); } Future restorePrivateKey(String password) { - return _channel.invokeMethod("restorePrivateKey", {'password': password}); + return _channel.invokeMethod('restorePrivateKey', { + 'password': password, + }); } Future rotatePrivateKey() { - return _channel.invokeMethod("rotatePrivateKey"); + return _channel.invokeMethod('rotatePrivateKey'); } Future hasLocalPrivateKey() { - return _channel.invokeMethod("hasLocalPrivateKey"); + return _channel.invokeMethod('hasLocalPrivateKey'); } Future cleanup() { - return _channel.invokeMethod("cleanup"); + return _channel.invokeMethod('cleanup'); } Future findUser(String identity) async { - final String? card = - await _channel.invokeMethod('findUser', {'identity': identity}); + final String? card = await _channel.invokeMethod('findUser', { + 'identity': identity, + }); return card; } Future findUsers(List identities, bool forceReload) async { - Map? users = await _channel.invokeMethod( - "findUsers", {"identities": identities, "forceReload": forceReload}); + Map? users = await _channel.invokeMethod('findUsers', { + 'identities': identities, + 'forceReload': forceReload, + }); return users; } Future findCachedUser(String identity) async { - final String? card = - await _channel.invokeMethod("findCachedUser", {'identity': identity}); + final String? card = await _channel.invokeMethod('findCachedUser', { + 'identity': identity, + }); return card; } Future findCachedUsers(List identities) async { - final Map? users = await _channel - .invokeMethod("findCachedUsers", {"identities": identities}); + final Map? users = await _channel.invokeMethod('findCachedUsers', { + 'identities': identities, + }); return users; } Future updateCachedUsers() { - return _channel.invokeMethod("updateCachedUsers"); + return _channel.invokeMethod('updateCachedUsers'); } Future authEncrypt(Map users, String data) { - return _channel.invokeMethod("authEncrypt", {"users": users, "data": data}); + return _channel.invokeMethod('authEncrypt', { + 'users': users, + 'data': data, + }); } - Future authDecrypt(String data, [String card = ""]) { - return _channel.invokeMethod("authDecrypt", {"data": data, "card": card}); + Future authDecrypt(String data, [String card = '']) { + return _channel.invokeMethod('authDecrypt', { + 'data': data, + 'card': card, + }); } Future _handleMethodCall(MethodCall call) { switch (call.method) { case 'tokenCallback': - return this.tokenCallback(); + return tokenCallback(); } - return Future.error("Unknown method ${call.method}"); + return Future.error('Unknown method ${call.method}'); } } From 5253692b5827a259b18d9efe759349694f046f7e Mon Sep 17 00:00:00 2001 From: Thomas Abot Date: Tue, 7 Dec 2021 09:49:34 +0100 Subject: [PATCH 6/6] Revert "Added analysis_options file" This reverts commit b71425101d1f9fd7805ef269890017ccaa28cce0. --- analysis_options.yaml | 86 ------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml deleted file mode 100644 index 0fee74b..0000000 --- a/analysis_options.yaml +++ /dev/null @@ -1,86 +0,0 @@ -analyzer: - strong-mode: - implicit-casts: false - implicit-dynamic: false - errors: - missing_required_param: error - missing_return: error - todo: warning - include_file_not_found: ignore - exclude: - # ignore warnings in files from json_serializable, built_value and most generators. - - "**/*.g.dart" - # ignore warnings in files generated by Freezed specifically. - - "**/*.freezed.dart" - # ignore warnings in files generated for localization. - - "**/generated/**/*.dart" -linter: - rules: - - annotate_overrides - - avoid_empty_else - - avoid_function_literals_in_foreach_calls - - avoid_init_to_null - - avoid_null_checks_in_equality_operators - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - - avoid_returning_null - - avoid_types_as_parameter_names - - avoid_unused_constructor_parameters - - await_only_futures - - camel_case_types - - cancel_subscriptions - - comment_references - - constant_identifier_names - - control_flow_in_finally - - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - - hash_and_equals - - implementation_imports - - invariant_booleans - - iterable_contains_unrelated_type - - library_names - - library_prefixes - - list_remove_unrelated_type - - no_adjacent_strings_in_list - - no_duplicate_case_values - - non_constant_identifier_names - - null_closures - - only_throw_errors - - overridden_fields - - package_api_docs - - package_names - - package_prefixed_library_names - - prefer_adjacent_string_concatenation - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_const_constructors - - prefer_contains - - prefer_equal_for_default_values - - prefer_final_fields - - prefer_initializing_formals - - prefer_interpolation_to_compose_strings - - prefer_is_empty - - prefer_is_not_empty - - prefer_single_quotes - - prefer_typing_uninitialized_variables - - recursive_getters - - require_trailing_commas - - slash_for_doc_comments - - test_types_in_equals - - throw_in_finally - - type_init_formals - - unawaited_futures - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - - unnecessary_lambdas - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_statements - - unnecessary_this - - unrelated_type_equality_checks - - use_rethrow_when_possible - - valid_regexps \ No newline at end of file