From dfe1d9003ea1cd2b2384382e6b2fe0a527c5a95f Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Wed, 16 Mar 2022 09:41:26 +0100 Subject: [PATCH] Credential id as String extension function --- .../kotlin/com/yubico/authenticator/MainViewModel.kt | 9 ++++----- .../kotlin/com/yubico/authenticator/SerializeHelpers.kt | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/MainViewModel.kt b/android/app/src/main/kotlin/com/yubico/authenticator/MainViewModel.kt index c9c4398e..1963d177 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/MainViewModel.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/MainViewModel.kt @@ -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) } diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/SerializeHelpers.kt b/android/app/src/main/kotlin/com/yubico/authenticator/SerializeHelpers.kt index c2a8afa9..01359b27 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/SerializeHelpers.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/SerializeHelpers.kt @@ -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),