mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +03:00
Credential id as String extension function
This commit is contained in:
parent
dfa8058b9d
commit
dfe1d9003e
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.yubico.authenticator.SerializeHelpers.Companion.idAsString
|
||||
import com.yubico.authenticator.SerializeHelpers.Companion.toJson
|
||||
import com.yubico.authenticator.api.Pigeon
|
||||
import com.yubico.yubikit.android.transport.nfc.NfcYubiKeyDevice
|
||||
@ -217,9 +218,7 @@ class MainViewModel : ViewModel() {
|
||||
|
||||
private fun getOathCredential(oathSession: OathSession, credentialId: String) =
|
||||
oathSession.credentials.firstOrNull { credential ->
|
||||
(credential != null) && SerializeHelpers.credentialIdAsString(
|
||||
credential.id
|
||||
) == credentialId
|
||||
(credential != null) && credential.idAsString() == credentialId
|
||||
} ?: throw Exception("Failed to find account to delete")
|
||||
|
||||
|
||||
@ -272,8 +271,8 @@ class MainViewModel : ViewModel() {
|
||||
|
||||
val jsonResult =
|
||||
session.renameCredential(credential, name, issuer)
|
||||
.toJson(session.deviceId)
|
||||
.toString()
|
||||
.toJson(session.deviceId)
|
||||
.toString()
|
||||
|
||||
result.success(jsonResult)
|
||||
}
|
||||
|
@ -74,16 +74,14 @@ class SerializeHelpers {
|
||||
)
|
||||
)
|
||||
|
||||
fun credentialIdAsString(id: ByteArray): String = id.joinToString(
|
||||
fun Credential.idAsString() = id.joinToString(
|
||||
separator = ""
|
||||
) { b -> "%02x".format(b) }
|
||||
|
||||
fun Credential.toJson(deviceId: String) =
|
||||
JsonObject(
|
||||
mapOf(
|
||||
"id" to JsonPrimitive(
|
||||
credentialIdAsString(id)
|
||||
),
|
||||
"id" to JsonPrimitive(idAsString()),
|
||||
"device_id" to JsonPrimitive(deviceId),
|
||||
"issuer" to JsonPrimitive(issuer),
|
||||
"name" to JsonPrimitive(accountName),
|
||||
|
Loading…
Reference in New Issue
Block a user