Add VaultSdkSource.getUserEncryptionKey (#545)

This commit is contained in:
Brian Yencho
2024-01-08 22:07:58 -06:00
committed by Álison Fernandes
parent 2d4427a7cf
commit 6686d98e34
3 changed files with 38 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import com.bitwarden.core.CollectionView
import com.bitwarden.core.Folder
import com.bitwarden.core.FolderView
import com.bitwarden.core.InitOrgCryptoRequest
import com.bitwarden.core.InitUserCryptoMethod
import com.bitwarden.core.InitUserCryptoRequest
import com.bitwarden.core.PasswordHistory
import com.bitwarden.core.PasswordHistoryView
@@ -27,6 +28,15 @@ interface VaultSdkSource {
*/
fun clearCrypto(userId: String)
/**
* Gets the user's encryption key, which can be used to later unlock their vault via a call to
* [initializeCrypto] with [InitUserCryptoMethod.DecryptedKey].
*
* This should only be called after a successful call to [initializeCrypto] for the associated
* user.
*/
suspend fun getUserEncryptionKey(userId: String): Result<String>
/**
* Attempts to initialize cryptography functionality for an individual user with the given
* [userId] for the Bitwarden SDK with a given [InitUserCryptoRequest].

View File

@@ -31,6 +31,15 @@ class VaultSdkSourceImpl(
sdkClientManager.destroyClient(userId = userId)
}
override suspend fun getUserEncryptionKey(
userId: String,
): Result<String> =
runCatching {
getClient(userId = userId)
.crypto()
.getUserEncryptionKey()
}
override suspend fun initializeCrypto(
userId: String,
request: InitUserCryptoRequest,