mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 09:25:58 +03:00
Add ability to decrypt Collections (#373)
This commit is contained in:
parent
79f1c2cd4c
commit
970e913373
3 changed files with 79 additions and 0 deletions
|
@ -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<Cipher>): Result<List<CipherView>>
|
||||
|
||||
/**
|
||||
* Decrypts a [Collection] returning a [CollectionView] wrapped in a [Result].
|
||||
*/
|
||||
suspend fun decryptCollection(collection: Collection): Result<CollectionView>
|
||||
|
||||
/**
|
||||
* Decrypts a list of [Collection]s returning a list of [CollectionView] wrapped in a [Result].
|
||||
*/
|
||||
suspend fun decryptCollectionList(
|
||||
collectionList: List<Collection>,
|
||||
): Result<List<CollectionView>>
|
||||
|
||||
/**
|
||||
* Decrypts a [Send] returning a [SendView] wrapped in a [Result].
|
||||
*/
|
||||
|
|
|
@ -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<Cipher>): Result<List<CipherView>> =
|
||||
runCatching { cipherList.map { clientVault.ciphers().decrypt(it) } }
|
||||
|
||||
override suspend fun decryptCollection(collection: Collection): Result<CollectionView> =
|
||||
runCatching {
|
||||
clientVault.collections().decrypt(collection)
|
||||
}
|
||||
|
||||
override suspend fun decryptCollectionList(
|
||||
collectionList: List<Collection>,
|
||||
): Result<List<CollectionView>> =
|
||||
runCatching {
|
||||
clientVault.collections().decryptList(collectionList)
|
||||
}
|
||||
|
||||
override suspend fun decryptSend(send: Send): Result<SendView> =
|
||||
runCatching { clientVault.sends().decrypt(send) }
|
||||
|
||||
|
|
|
@ -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<Collection>()
|
||||
val expectedResult = mockk<CollectionView>()
|
||||
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<List<Collection>>()
|
||||
val expectedResult = mockk<List<CollectionView>>()
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue