Jelajahi Sumber

Handle null values for mem/ops limit in local storage

Neeraj Gupta 2 tahun lalu
induk
melakukan
8ebc5e49b5

+ 4 - 4
lib/core/configuration.dart

@@ -273,8 +273,8 @@ class Configuration {
     final kek = await CryptoUtil.deriveKey(
       utf8.encode(password) as Uint8List,
       Sodium.base642bin(attributes.kekSalt),
-      attributes.memLimit,
-      attributes.opsLimit,
+      attributes.memLimit!,
+      attributes.opsLimit!,
     ).onError((e, s) {
       _logger.severe('deriveKey failed', e, s);
       throw KeyDerivationError();
@@ -318,8 +318,8 @@ class Configuration {
     final kek = await CryptoUtil.deriveKey(
       utf8.encode(password) as Uint8List,
       Sodium.base642bin(attributes.kekSalt),
-      attributes.memLimit,
-      attributes.opsLimit,
+      attributes.memLimit!,
+      attributes.opsLimit!,
     ).onError((e, s) {
       _logger.severe('deriveKey failed', e, s);
       throw KeyDerivationError();

+ 2 - 2
lib/models/key_attributes.dart

@@ -7,8 +7,8 @@ class KeyAttributes {
   final String publicKey;
   final String encryptedSecretKey;
   final String secretKeyDecryptionNonce;
-  final int memLimit;
-  final int opsLimit;
+  final int? memLimit;
+  final int? opsLimit;
   final String masterKeyEncryptedWithRecoveryKey;
   final String masterKeyDecryptionNonce;
   final String? recoveryKeyEncryptedWithMasterKey;

+ 2 - 2
lib/services/user_service.dart

@@ -397,8 +397,8 @@ class UserService {
         kekSalt: keyAttributes.kekSalt,
         encryptedKey: keyAttributes.encryptedKey,
         keyDecryptionNonce: keyAttributes.keyDecryptionNonce,
-        memLimit: keyAttributes.memLimit,
-        opsLimit: keyAttributes.opsLimit,
+        memLimit: keyAttributes.memLimit!,
+        opsLimit: keyAttributes.opsLimit!,
       );
       await _enteDio.put(
         "/users/keys",

+ 4 - 1
lib/utils/validator_util.dart

@@ -25,7 +25,10 @@ void validatePreVerificationStateCheck(
     "secretKeyDecryptionNonce",
   );
   nullOrEmptyArgCheck(keyAttr.publicKey, "publicKey");
-  if (keyAttr.memLimit <= 0 || keyAttr.opsLimit <= 0) {
+  if (keyAttr.memLimit == null || keyAttr.opsLimit == null) {
+    throw ArgumentError("Key mem/OpsLimit can not be null");
+  }
+  if (keyAttr.memLimit! <= 0 || keyAttr.opsLimit! <= 0) {
     throw ArgumentError("Key mem/OpsLimit can not be <0");
   }
   // check password encoding issues