mirror of
https://github.com/bitwarden/android.git
synced 2026-06-06 14:28:45 -05:00
Add method for encrypting an attachment (#774)
This commit is contained in:
committed by
Álison Fernandes
parent
cc7da7b8dd
commit
6f9147b2b2
@@ -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].
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user