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

commonMain.at.asitplus.wallet.lib.oidvci.CredentialFormatEnum.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 kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable(with = CredentialFormatSerializer::class)
enum class CredentialFormatEnum(val text: String) {
    NONE("none"),
    JWT_VC("jwt_vc_json"),
    /**
     * Unofficial constant, used by this library prior to implementing OID4VCI Draft 13.
     */
    JWT_VC_SD_UNOFFICIAL("jwt_vc_sd"),
    VC_SD_JWT("vc+sd-jwt"),
    JWT_VC_JSON_LD("jwt_vc_json-ld"),
    JSON_LD("ldp_vc"),
    MSO_MDOC("mso_mdoc");

    companion object {
        fun parse(text: String) = entries.firstOrNull { it.text == text }
    }
}

object CredentialFormatSerializer : KSerializer {

    override val descriptor: SerialDescriptor =
        PrimitiveSerialDescriptor("CredentialFormatEnumSerializer", PrimitiveKind.STRING)

    override fun serialize(encoder: Encoder, value: CredentialFormatEnum) {
        encoder.encodeString(value.text)
    }

    override fun deserialize(decoder: Decoder): CredentialFormatEnum {
        return CredentialFormatEnum.parse(decoder.decodeString()) ?: CredentialFormatEnum.NONE
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy