generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
AuthenticatorSdkSourceImpl.kt
48 lines (42 loc) · 1.5 KB
/
AuthenticatorSdkSourceImpl.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.bitwarden.authenticator.data.authenticator.datasource.sdk
import com.bitwarden.authenticator.data.platform.manager.SdkClientManager
import com.bitwarden.core.DateTime
import com.bitwarden.core.TotpResponse
import com.bitwarden.generators.PasswordGeneratorRequest
import com.bitwarden.sdk.Client
import javax.inject.Inject
class AuthenticatorSdkSourceImpl @Inject constructor(
private val sdkClientManager: SdkClientManager,
) : AuthenticatorSdkSource {
override suspend fun generateTotp(
totp: String,
time: DateTime,
): Result<TotpResponse> = runCatching {
getClient()
.vault()
.generateTotp(
key = totp,
time = time,
)
}
override suspend fun generateBiometricsKey(): Result<String> =
runCatching {
getClient()
.generators()
.password(
PasswordGeneratorRequest(
lowercase = true,
uppercase = true,
numbers = true,
special = true,
length = 7.toUByte(),
avoidAmbiguous = true,
minLowercase = null,
minUppercase = null,
minNumber = null,
minSpecial = null
)
)
}
private suspend fun getClient(): Client = sdkClientManager.getOrCreateClient()
}