mirror of
https://github.com/bitwarden/android.git
synced 2025-02-16 20:09:59 +03:00
Add support for encrypting sends (#515)
This commit is contained in:
parent
9aca107183
commit
d00e7d69ea
3 changed files with 41 additions and 0 deletions
|
@ -120,6 +120,18 @@ interface VaultSdkSource {
|
|||
collectionList: List<Collection>,
|
||||
): Result<List<CollectionView>>
|
||||
|
||||
/**
|
||||
* Encrypts a [SendView] for the user with the given [userId], returning a [Send] wrapped
|
||||
* in a [Result].
|
||||
*
|
||||
* This should only be called after a successful call to [initializeCrypto] for the associated
|
||||
* user.
|
||||
*/
|
||||
suspend fun encryptSend(
|
||||
userId: String,
|
||||
sendView: SendView,
|
||||
): Result<Send>
|
||||
|
||||
/**
|
||||
* Decrypts a [Send] for the user with the given [userId], returning a [SendView] wrapped in a
|
||||
* [Result].
|
||||
|
|
|
@ -63,6 +63,17 @@ class VaultSdkSourceImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun encryptSend(
|
||||
userId: String,
|
||||
sendView: SendView,
|
||||
): Result<Send> =
|
||||
runCatching {
|
||||
getClient(userId = userId)
|
||||
.vault()
|
||||
.sends()
|
||||
.encrypt(sendView)
|
||||
}
|
||||
|
||||
override suspend fun encryptCipher(
|
||||
userId: String,
|
||||
cipherView: CipherView,
|
||||
|
|
|
@ -403,6 +403,24 @@ class VaultSdkSourceTest {
|
|||
verify { sdkClientManager.getOrCreateClient(userId = userId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `encryptSend should call SDK and return correct data wrapped in a Result`() = runBlocking {
|
||||
val userId = "userId"
|
||||
val expectedResult = mockk<Send>()
|
||||
val mockSendView = mockk<SendView>()
|
||||
coEvery { clientVault.sends().encrypt(send = mockSendView) } returns expectedResult
|
||||
|
||||
val result = vaultSdkSource.encryptSend(
|
||||
userId = userId,
|
||||
sendView = mockSendView,
|
||||
)
|
||||
|
||||
assertEquals(expectedResult.asSuccess(), result)
|
||||
coVerify {
|
||||
clientVault.sends().encrypt(send = mockSendView)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decryptSend should call SDK and return correct data wrapped in a Result`() =
|
||||
runBlocking {
|
||||
|
|
Loading…
Add table
Reference in a new issue