Move computer initialization to CryptoUtil
This commit is contained in:
parent
70f5fbacd7
commit
b6e5e810b3
2 changed files with 13 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:background_fetch/background_fetch.dart';
|
||||
import 'package:computer/computer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
@ -12,6 +11,7 @@ import 'package:photos/services/collections_service.dart';
|
|||
import 'package:photos/services/memories_service.dart';
|
||||
import 'package:photos/services/sync_service.dart';
|
||||
import 'package:photos/ui/home_widget.dart';
|
||||
import 'package:photos/utils/crypto_util.dart';
|
||||
import 'package:sentry/sentry.dart';
|
||||
import 'package:super_logging/super_logging.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -48,8 +48,8 @@ void _main() async {
|
|||
|
||||
Future _init() async {
|
||||
_logger.info("Initializing...");
|
||||
Computer().turnOn(workersCount: 4);
|
||||
InAppPurchaseConnection.enablePendingPurchases();
|
||||
CryptoUtil.init();
|
||||
await Configuration.instance.init();
|
||||
await BillingService.instance.init();
|
||||
await CollectionsService.instance.init();
|
||||
|
|
|
@ -96,6 +96,12 @@ void chachaDecrypt(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
class CryptoUtil {
|
||||
static Computer _computer = Computer();
|
||||
|
||||
static init() {
|
||||
_computer.turnOn(workersCount: 4);
|
||||
}
|
||||
|
||||
static EncryptionResult encryptSync(Uint8List source, Uint8List key) {
|
||||
final nonce = Sodium.randombytesBuf(Sodium.cryptoSecretboxNoncebytes);
|
||||
|
||||
|
@ -117,7 +123,7 @@ class CryptoUtil {
|
|||
args["cipher"] = cipher;
|
||||
args["nonce"] = nonce;
|
||||
args["key"] = key;
|
||||
return Computer().compute(cryptoSecretboxOpenEasy, param: args);
|
||||
return _computer.compute(cryptoSecretboxOpenEasy, param: args);
|
||||
}
|
||||
|
||||
static Uint8List decryptSync(
|
||||
|
@ -162,7 +168,7 @@ class CryptoUtil {
|
|||
args["sourceFilePath"] = sourceFilePath;
|
||||
args["destinationFilePath"] = destinationFilePath;
|
||||
args["key"] = key;
|
||||
return Computer().compute(chachaEncryptFile, param: args);
|
||||
return _computer.compute(chachaEncryptFile, param: args);
|
||||
}
|
||||
|
||||
static Future<void> decryptFile(
|
||||
|
@ -176,7 +182,7 @@ class CryptoUtil {
|
|||
args["destinationFilePath"] = destinationFilePath;
|
||||
args["header"] = header;
|
||||
args["key"] = key;
|
||||
return Computer().compute(chachaDecrypt, param: args);
|
||||
return _computer.compute(chachaDecrypt, param: args);
|
||||
}
|
||||
|
||||
static Uint8List generateKey() {
|
||||
|
@ -203,14 +209,14 @@ class CryptoUtil {
|
|||
args["input"] = input;
|
||||
args["opsLimit"] = Sodium.cryptoPwhashOpslimitSensitive;
|
||||
args["memLimit"] = Sodium.cryptoPwhashMemlimitModerate;
|
||||
return utf8.decode(await Computer().compute(cryptoPwhashStr, param: args));
|
||||
return utf8.decode(await _computer.compute(cryptoPwhashStr, param: args));
|
||||
}
|
||||
|
||||
static Future<bool> verifyHash(Uint8List input, String hash) async {
|
||||
final args = Map<String, dynamic>();
|
||||
args["input"] = input;
|
||||
args["hash"] = utf8.encode(hash);
|
||||
return await Computer().compute(cryptoPwhashStrVerify, param: args);
|
||||
return await _computer.compute(cryptoPwhashStrVerify, param: args);
|
||||
}
|
||||
|
||||
static Future<KeyPair> generateKeyPair() async {
|
||||
|
|
Loading…
Add table
Reference in a new issue