Add method for encrypting an attachment (#774)

This commit is contained in:
David Perez
2024-01-25 10:33:54 -06:00
committed by Álison Fernandes
parent cc7da7b8dd
commit 6f9147b2b2
3 changed files with 71 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package com.x8bit.bitwarden.data.vault.datasource.sdk
import com.bitwarden.core.AttachmentEncryptResult
import com.bitwarden.core.AttachmentView
import com.bitwarden.core.Cipher
import com.bitwarden.core.CipherListView
import com.bitwarden.core.CipherView
@@ -87,6 +89,20 @@ interface VaultSdkSource {
request: InitOrgCryptoRequest,
): Result<InitializeCryptoResult>
/**
* Encrypts a [AttachmentView] for the user with the given [userId], returning an
* [AttachmentEncryptResult] wrapped in a [Result].
*
* This should only be called after a successful call to [initializeCrypto] for the associated
* user.
*/
suspend fun encryptAttachment(
userId: String,
cipher: Cipher,
attachmentView: AttachmentView,
fileBuffer: ByteArray,
): Result<AttachmentEncryptResult>
/**
* Encrypts a [CipherView] for the user with the given [userId], returning a [Cipher] wrapped
* in a [Result].

View File

@@ -1,5 +1,7 @@
package com.x8bit.bitwarden.data.vault.datasource.sdk
import com.bitwarden.core.AttachmentEncryptResult
import com.bitwarden.core.AttachmentView
import com.bitwarden.core.Cipher
import com.bitwarden.core.CipherListView
import com.bitwarden.core.CipherView
@@ -121,6 +123,23 @@ class VaultSdkSourceImpl(
)
}
override suspend fun encryptAttachment(
userId: String,
cipher: Cipher,
attachmentView: AttachmentView,
fileBuffer: ByteArray,
): Result<AttachmentEncryptResult> =
runCatching {
getClient(userId = userId)
.vault()
.attachments()
.encryptBuffer(
cipher = cipher,
attachment = attachmentView,
buffer = fileBuffer,
)
}
override suspend fun encryptCipher(
userId: String,
cipherView: CipherView,