diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSource.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSource.kt index 5ef513f7e..4f09b390b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSource.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSource.kt @@ -3,6 +3,8 @@ package com.x8bit.bitwarden.data.vault.datasource.sdk import com.bitwarden.core.Cipher import com.bitwarden.core.CipherListView import com.bitwarden.core.CipherView +import com.bitwarden.core.Collection +import com.bitwarden.core.CollectionView import com.bitwarden.core.Folder import com.bitwarden.core.FolderView import com.bitwarden.core.InitUserCryptoRequest @@ -13,6 +15,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.InitializeCryptoResul /** * Source of vault information and functionality from the Bitwarden SDK. */ +@Suppress("TooManyFunctions") interface VaultSdkSource { /** @@ -41,6 +44,18 @@ interface VaultSdkSource { */ suspend fun decryptCipherList(cipherList: List): Result> + /** + * Decrypts a [Collection] returning a [CollectionView] wrapped in a [Result]. + */ + suspend fun decryptCollection(collection: Collection): Result + + /** + * Decrypts a list of [Collection]s returning a list of [CollectionView] wrapped in a [Result]. + */ + suspend fun decryptCollectionList( + collectionList: List, + ): Result> + /** * Decrypts a [Send] returning a [SendView] wrapped in a [Result]. */ diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceImpl.kt index 4e3acb09b..6f2eead36 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceImpl.kt @@ -3,6 +3,8 @@ package com.x8bit.bitwarden.data.vault.datasource.sdk import com.bitwarden.core.Cipher import com.bitwarden.core.CipherListView import com.bitwarden.core.CipherView +import com.bitwarden.core.Collection +import com.bitwarden.core.CollectionView import com.bitwarden.core.Folder import com.bitwarden.core.FolderView import com.bitwarden.core.InitUserCryptoRequest @@ -17,6 +19,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.InitializeCryptoResul * Primary implementation of [VaultSdkSource] that serves as a convenience wrapper around a * [ClientVault]. */ +@Suppress("TooManyFunctions") class VaultSdkSourceImpl( private val clientVault: ClientVault, private val clientCrypto: ClientCrypto, @@ -48,6 +51,18 @@ class VaultSdkSourceImpl( override suspend fun decryptCipherList(cipherList: List): Result> = runCatching { cipherList.map { clientVault.ciphers().decrypt(it) } } + override suspend fun decryptCollection(collection: Collection): Result = + runCatching { + clientVault.collections().decrypt(collection) + } + + override suspend fun decryptCollectionList( + collectionList: List, + ): Result> = + runCatching { + clientVault.collections().decryptList(collectionList) + } + override suspend fun decryptSend(send: Send): Result = runCatching { clientVault.sends().decrypt(send) } diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceTest.kt index bffc0c680..4264a84d9 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/sdk/VaultSdkSourceTest.kt @@ -3,6 +3,8 @@ package com.x8bit.bitwarden.data.vault.datasource.sdk import com.bitwarden.core.Cipher import com.bitwarden.core.CipherListView import com.bitwarden.core.CipherView +import com.bitwarden.core.Collection +import com.bitwarden.core.CollectionView import com.bitwarden.core.Folder import com.bitwarden.core.FolderView import com.bitwarden.core.InitUserCryptoRequest @@ -192,6 +194,53 @@ class VaultSdkSourceTest { } } + @Test + fun `decryptCollection should call SDK and return correct data wrapped in a Result`() = + runBlocking { + val mockCollection = mockk() + val expectedResult = mockk() + coEvery { + clientVault.collections().decrypt( + collection = mockCollection, + ) + } returns expectedResult + val result = vaultSdkSource.decryptCollection( + collection = mockCollection, + ) + assertEquals( + expectedResult.asSuccess(), result, + ) + coVerify { + clientVault.collections().decrypt( + collection = mockCollection, + ) + } + } + + @Test + fun `decryptCollectionList should call SDK and return correct data wrapped in a Result`() = + runBlocking { + val mockCollectionsList = mockk>() + val expectedResult = mockk>() + coEvery { + clientVault.collections().decryptList( + collections = mockCollectionsList, + ) + } returns expectedResult + val result = vaultSdkSource.decryptCollectionList( + collectionList = mockCollectionsList, + ) + assertEquals( + expectedResult.asSuccess(), + result, + ) + coVerify { + clientVault.collections().decryptList( + collections = mockCollectionsList, + ) + } + } + @Test fun `decryptSendList should call SDK and return correct data wrapped in a Result`() = runBlocking {