فهرست منبع

Explicitly state the sync nature of the encryption API

Vishnu Mohandas 4 سال پیش
والد
کامیت
bae5c9bf7d
3فایلهای تغییر یافته به همراه6 افزوده شده و 7 حذف شده
  1. 3 3
      lib/core/configuration.dart
  2. 2 3
      lib/utils/crypto_util.dart
  3. 1 1
      lib/utils/file_uploader.dart

+ 3 - 3
lib/core/configuration.dart

@@ -47,7 +47,7 @@ class Configuration {
 
   Future<KeyAttributes> generateAndSaveKey(String passphrase) async {
     // Create a master key
-    final key = CryptoUtil.generateMasterKey();
+    final key = CryptoUtil.generateKey();
 
     // Derive a key from the passphrase that will be used to encrypt and
     // decrypt the master key
@@ -55,14 +55,14 @@ class Configuration {
     final kek = CryptoUtil.deriveKey(utf8.encode(passphrase), kekSalt);
 
     // Encrypt the key with this derived key
-    final encryptedKeyData = await CryptoUtil.encrypt(key, kek);
+    final encryptedKeyData = CryptoUtil.encryptSync(key, kek);
 
     // Hash the passphrase so that its correctness can be compared later
     final kekHash = await CryptoUtil.hash(kek);
 
     // Generate a public-private keypair and encrypt the latter
     final keyPair = await CryptoUtil.generateKeyPair();
-    final encryptedSecretKeyData = await CryptoUtil.encrypt(keyPair.sk, kek);
+    final encryptedSecretKeyData = CryptoUtil.encryptSync(keyPair.sk, kek);
 
     final attributes = KeyAttributes(
       Sodium.bin2base64(kekSalt),

+ 2 - 3
lib/utils/crypto_util.dart

@@ -96,8 +96,7 @@ void chachaDecrypt(Map<String, dynamic> args) {
 }
 
 class CryptoUtil {
-  static Future<EncryptionResult> encrypt(
-      Uint8List source, Uint8List key) async {
+  static EncryptionResult encryptSync(Uint8List source, Uint8List key) {
     final nonce = Sodium.randombytesBuf(Sodium.cryptoSecretboxNoncebytes);
 
     final args = Map<String, dynamic>();
@@ -178,7 +177,7 @@ class CryptoUtil {
     return Computer().compute(chachaDecrypt, param: args);
   }
 
-  static Uint8List generateMasterKey() {
+  static Uint8List generateKey() {
     return Sodium.cryptoSecretboxKeygen();
   }
 

+ 1 - 1
lib/utils/file_uploader.dart

@@ -76,7 +76,7 @@ class FileUploader {
     final encryptedMetadataData = CryptoUtil.encryptChaCha(
         utf8.encode(jsonEncode(file.getMetadata())), fileAttributes.key);
 
-    final encryptedFileKeyData = await CryptoUtil.encrypt(
+    final encryptedFileKeyData = CryptoUtil.encryptSync(
       fileAttributes.key,
       Configuration.instance.getKey(),
     );