Add support for encrypting sends (#515)

This commit is contained in:
David Perez 2024-01-06 21:18:59 -06:00 committed by Álison Fernandes
parent 9aca107183
commit d00e7d69ea
3 changed files with 41 additions and 0 deletions

View file

@ -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].

View file

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

View file

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