commonMain.at.asitplus.wallet.lib.oidvci.OidcUserInfoExtended.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vck-openid Show documentation
Show all versions of vck-openid Show documentation
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()
}
}