DeviceInfo to json extension function

This commit is contained in:
Adam Velebil 2022-03-16 09:32:51 +01:00
parent 6c3674c72d
commit 35ecc03680
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
2 changed files with 20 additions and 22 deletions

View File

@ -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)

View File

@ -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(