Add support for encrypting sends (#515)

This commit is contained in:
David Perez authored and Álison Fernandes committed 2024-06-20 17:08:07 +01:00
1 parent 9aca107183
commit d00e7d69ea
3 files changed
+41

No files matched your search

@@ -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 {