Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate lib to null safety #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
111 changes: 65 additions & 46 deletions lib/virgil_e3kit.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import 'dart:async';
import 'dart:math';
import 'dart:convert';
import 'dart:math';

import 'package:flutter/services.dart';

typedef GetJWTCallback = Future<dynamic> Function();
final MethodChannel globalChannel = MethodChannel('com.virgilsecurity/ethree');
final MethodChannel globalChannel =
const MethodChannel('com.virgilsecurity/ethree');

class Ethree {
final MethodChannel _channel;
final GetJWTCallback tokenCallback;
final String identity;

Ethree(this.identity, this.tokenCallback, this._channel) {
this._channel.setMethodCallHandler(this.handleMethodCall);
_channel.setMethodCallHandler(_handleMethodCall);
}

static Future<Ethree> init(
String identity, GetJWTCallback tokenCallback) async {
static Future<Ethree?> 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;
Expand All @@ -30,93 +34,108 @@ class Ethree {
return ethree;
}

Future<String> getIdentity() async {
Future<String?> getIdentity() {
return _channel.invokeMethod('getIdentity');
}

Future<bool> register() async {
Future<bool?> register() {
return _channel.invokeMethod('register');
}

Future<bool> unregister() async {
return _channel.invokeMethod("unregister");
Future<bool?> unregister() {
return _channel.invokeMethod('unregister');
}

Future<bool> backupPrivateKey(String password) async {
return _channel.invokeMethod("backupPrivateKey", {"password": password});
Future<bool?> backupPrivateKey(String password) {
return _channel.invokeMethod('backupPrivateKey', {'password': password});
}

Future<bool> changePassword(String oldPassword, String newPassword) async {
return _channel.invokeMethod("changePassword",
{"oldPassword": oldPassword, "newPassword": newPassword});
Future<bool?> changePassword(String oldPassword, String newPassword) {
return _channel.invokeMethod('changePassword', {
'oldPassword': oldPassword,
'newPassword': newPassword,
});
}

Future<bool> resetPrivateKeyBackup() async {
return _channel.invokeMethod("resetPrivateKeyBackup");
Future<bool?> resetPrivateKeyBackup() {
return _channel.invokeMethod('resetPrivateKeyBackup');
}

Future<bool> restorePrivateKey(String password) async {
return _channel.invokeMethod("restorePrivateKey", {'password': password});
Future<bool?> restorePrivateKey(String password) {
return _channel.invokeMethod('restorePrivateKey', {
'password': password,
});
}

Future<bool> rotatePrivateKey() async {
return _channel.invokeMethod("rotatePrivateKey");
Future<bool?> rotatePrivateKey() {
return _channel.invokeMethod('rotatePrivateKey');
}

Future<bool> hasLocalPrivateKey() async {
return _channel.invokeMethod("hasLocalPrivateKey");
Future<bool?> hasLocalPrivateKey() {
return _channel.invokeMethod('hasLocalPrivateKey');
}

Future<bool> cleanup() async {
return _channel.invokeMethod("cleanup");
Future<bool?> cleanup() {
return _channel.invokeMethod('cleanup');
}

Future<String> findUser(String identity) async {
final String card =
await _channel.invokeMethod('findUser', {'identity': identity});
Future<String?> findUser(String identity) async {
final String? card = await _channel.invokeMethod('findUser', {
'identity': identity,
});

return card;
}

Future<Map> findUsers(List<String> identities, bool forceReload) async {
Map users = await _channel.invokeMethod(
"findUsers", {"identities": identities, "forceReload": forceReload});
Future<Map?> findUsers(List<String> identities, bool forceReload) async {
Map? users = await _channel.invokeMethod('findUsers', {
'identities': identities,
'forceReload': forceReload,
});

return users;
}

Future<String> findCachedUser(String identity) async {
final String card =
await _channel.invokeMethod("findCachedUser", {'identity': identity});
Future<String?> findCachedUser(String identity) async {
final String? card = await _channel.invokeMethod('findCachedUser', {
'identity': identity,
});

return card;
}

Future<Map> findCachedUsers(List<String> identities) async {
final Map users = await _channel
.invokeMethod("findCachedUsers", {"identities": identities});
Future<Map?> findCachedUsers(List<String> identities) async {
final Map? users = await _channel.invokeMethod('findCachedUsers', {
'identities': identities,
});

return users;
}

Future<bool> updateCachedUsers() async {
return _channel.invokeMethod("updateCachedUsers");
Future<bool?> updateCachedUsers() {
return _channel.invokeMethod('updateCachedUsers');
}

Future<String> authEncrypt(Map users, String data) async {
return _channel.invokeMethod("authEncrypt", {"users": users, "data": data});
Future<String?> authEncrypt(Map users, String data) {
return _channel.invokeMethod('authEncrypt', {
'users': users,
'data': data,
});
}

Future<String> authDecrypt(String data, [String card = ""]) async {
return _channel.invokeMethod("authDecrypt", {"data": data, "card": card});
Future<String?> authDecrypt(String data, [String card = '']) {
return _channel.invokeMethod('authDecrypt', {
'data': data,
'card': card,
});
}

Future<dynamic> handleMethodCall(MethodCall call) {
Future<dynamic> _handleMethodCall(MethodCall call) {
switch (call.method) {
case 'tokenCallback':
return this.tokenCallback();
return tokenCallback();
}
return null;
return Future<dynamic>.error('Unknown method ${call.method}');
}
}

Expand Down
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down