mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +03:00
DeviceInfo to json extension function
This commit is contained in:
parent
6c3674c72d
commit
35ecc03680
@ -83,9 +83,10 @@ class MainViewModel : ViewModel() {
|
||||
|
||||
try {
|
||||
val deviceInfo = managementSession.deviceInfo
|
||||
val deviceInfoData =
|
||||
SerializeHelpers.serialize(deviceInfo, device is NfcYubiKeyDevice)
|
||||
it.resume(deviceInfoData.toString())
|
||||
val deviceInfoData = deviceInfo
|
||||
.toJson(device is NfcYubiKeyDevice)
|
||||
.toString()
|
||||
it.resume(deviceInfoData)
|
||||
} catch (cause: Throwable) {
|
||||
Logger.e("Failed to get device info", cause)
|
||||
it.resumeWithException(cause)
|
||||
|
@ -40,28 +40,25 @@ class SerializeHelpers {
|
||||
)
|
||||
}
|
||||
|
||||
fun serialize(data: DeviceInfo, isNfcDevice: Boolean) =
|
||||
with(data) {
|
||||
JsonObject(
|
||||
fun DeviceInfo.toJson(isNfcDevice: Boolean) = JsonObject(
|
||||
mapOf(
|
||||
"config" to serialize(config),
|
||||
"serial" to JsonPrimitive(serialNumber),
|
||||
"version" to serialize(version),
|
||||
"form_factor" to JsonPrimitive(formFactor.value),
|
||||
"is_locked" to JsonPrimitive(isLocked),
|
||||
"is_sky" to JsonPrimitive(false), // FIXME return correct value
|
||||
"is_fips" to JsonPrimitive(false), // FIXME return correct value
|
||||
"name" to JsonPrimitive("FIXME"), // FIXME return correct value
|
||||
"isNFC" to JsonPrimitive(isNfcDevice),
|
||||
"supported_capabilities" to JsonObject(
|
||||
mapOf(
|
||||
"config" to serialize(config),
|
||||
"serial" to JsonPrimitive(serialNumber),
|
||||
"version" to serialize(version),
|
||||
"form_factor" to JsonPrimitive(formFactor.value),
|
||||
"is_locked" to JsonPrimitive(isLocked),
|
||||
"is_sky" to JsonPrimitive(false), // FIXME return correct value
|
||||
"is_fips" to JsonPrimitive(false), // FIXME return correct value
|
||||
"name" to JsonPrimitive("FIXME"), // FIXME return correct value
|
||||
"isNFC" to JsonPrimitive(isNfcDevice),
|
||||
"supported_capabilities" to JsonObject(
|
||||
mapOf(
|
||||
"usb" to JsonPrimitive(getSupportedCapabilities(Transport.USB)),
|
||||
"nfc" to JsonPrimitive(getSupportedCapabilities(Transport.NFC)),
|
||||
)
|
||||
)
|
||||
"usb" to JsonPrimitive(getSupportedCapabilities(Transport.USB)),
|
||||
"nfc" to JsonPrimitive(getSupportedCapabilities(Transport.NFC)),
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
fun OathSession.toJson(remembered: Boolean) = JsonObject(
|
||||
mapOf(
|
||||
|
Loading…
Reference in New Issue
Block a user