Add VaultSdkSource.derivePinKey (#609)

This commit is contained in:
Brian Yencho
2024-01-14 14:32:43 -06:00
committed by Álison Fernandes
parent 32c1c2155e
commit c59ae03f97
3 changed files with 47 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import com.bitwarden.core.CipherListView
import com.bitwarden.core.CipherView
import com.bitwarden.core.Collection
import com.bitwarden.core.CollectionView
import com.bitwarden.core.DerivePinKeyResponse
import com.bitwarden.core.Folder
import com.bitwarden.core.FolderView
import com.bitwarden.core.InitOrgCryptoRequest
@@ -28,6 +29,18 @@ interface VaultSdkSource {
*/
fun clearCrypto(userId: String)
/**
* Derives a "pin key" from the given [pin] for the given [userId]. This can be used to later
* unlock their vault via a call to [initializeCrypto] with [InitUserCryptoMethod.Pin].
*
* This should only be called after a successful call to [initializeCrypto] for the associated
* user.
*/
suspend fun derivePinKey(
userId: String,
pin: String,
): Result<DerivePinKeyResponse>
/**
* Gets the user's encryption key, which can be used to later unlock their vault via a call to
* [initializeCrypto] with [InitUserCryptoMethod.DecryptedKey].

View File

@@ -5,6 +5,7 @@ import com.bitwarden.core.CipherListView
import com.bitwarden.core.CipherView
import com.bitwarden.core.Collection
import com.bitwarden.core.CollectionView
import com.bitwarden.core.DerivePinKeyResponse
import com.bitwarden.core.Folder
import com.bitwarden.core.FolderView
import com.bitwarden.core.InitOrgCryptoRequest
@@ -31,6 +32,16 @@ class VaultSdkSourceImpl(
sdkClientManager.destroyClient(userId = userId)
}
override suspend fun derivePinKey(
userId: String,
pin: String,
): Result<DerivePinKeyResponse> =
runCatching {
getClient(userId = userId)
.crypto()
.derivePinKey(pin = pin)
}
override suspend fun getUserEncryptionKey(
userId: String,
): Result<String> =