All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.at.asitplus.wallet.lib.oidvci.OidcUserInfoExtended.kt Maven / Gradle / Ivy

Go to download

Kotlin Multiplatform library implementing the W3C VC Data Model, with OpenId protocol implementations

The newest version!
package at.asitplus.wallet.lib.oidvci

import at.asitplus.KmmResult
import at.asitplus.KmmResult.Companion.wrap
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.encodeToJsonElement

/**
 * Holds a deserialized [OidcUserInfo] as well as a [JsonObject] with other properties,
 * that could not been parsed.
 */
data class OidcUserInfoExtended(
    val userInfo: OidcUserInfo,
    val jsonObject: JsonObject,
) {
    companion object {
        fun deserialize(it: String): KmmResult =
            runCatching {
                val jsonObject = jsonSerializer.decodeFromString(it)
                val userInfo = jsonSerializer.decodeFromJsonElement(jsonObject)
                OidcUserInfoExtended(userInfo, jsonObject)
            }.wrap()

        fun fromOidcUserInfo(userInfo: OidcUserInfo): KmmResult =
            runCatching {
                OidcUserInfoExtended(userInfo, jsonSerializer.encodeToJsonElement(userInfo) as JsonObject)
            }.wrap()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy