From dca63ca487d32d5dd9826083a8c49d93588a5641 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Thu, 18 Apr 2024 23:00:08 +0530 Subject: [PATCH] fix: get collection key correctly --- .../lib/module/upload/service/multipart.dart | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/mobile/lib/module/upload/service/multipart.dart b/mobile/lib/module/upload/service/multipart.dart index 450335cf25..b1f4d317ea 100644 --- a/mobile/lib/module/upload/service/multipart.dart +++ b/mobile/lib/module/upload/service/multipart.dart @@ -31,21 +31,21 @@ class MultiPartUploader { String fileHash, int collectionID, ) async { - final collection = - CollectionsService.instance.getCollectionByID(collectionID); - if (collection == null) { - throw Exception("Collection not found"); - } + final collectionKey = + CollectionsService.instance.getCollectionKey(collectionID); final result = await _db.getFileEncryptionData(localId, fileHash, collectionID); final encryptedFileKey = CryptoUtil.base642bin(result.encryptedFileKey); final fileNonce = CryptoUtil.base642bin(result.fileNonce); - final key = CryptoUtil.base642bin(collection.encryptedKey); final encryptKeyNonce = CryptoUtil.base642bin(result.keyNonce); return EncryptionResult( - key: CryptoUtil.decryptSync(encryptedFileKey, key, encryptKeyNonce), + key: CryptoUtil.decryptSync( + encryptedFileKey, + collectionKey, + encryptKeyNonce, + ), nonce: fileNonce, ); } @@ -96,15 +96,12 @@ class MultiPartUploader { Uint8List fileKey, Uint8List fileNonce, ) async { - final collection = - CollectionsService.instance.getCollectionByID(collectionID); - if (collection == null) { - throw Exception("Collection not found"); - } + final collectionKey = + CollectionsService.instance.getCollectionKey(collectionID); final encryptedResult = CryptoUtil.encryptSync( fileKey, - CryptoUtil.base642bin(collection.encryptedKey), + collectionKey, ); await _db.createTrackUploadsEntry(