Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more tests #7

Merged
merged 13 commits into from
Oct 2, 2024
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Powered by VC-K](https://img.shields.io/badge/VC--K-powered-8A2BE2?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4LjAzIDkuNSI+PGcgZmlsbD0iIzhhMmJlMiIgZm9udC1mYW1pbHk9IlZBTE9SQU5UIiBmb250LXNpemU9IjEyLjciIHRleHQtYW5jaG9yPSJtaWRkbGUiPjxwYXRoIGQ9Ik01OS42NCAyMjIuMTNxMC0uOTguMzYtMS44Mi4zNy0uODQuOTgtMS40Ni42Mi0uNjIgMS40Ni0uOTYuODMtLjM2IDEuOC0uMzUgMS4wMy4wMiAxLjkuNDIuODcuNCAxLjUgMS4xMi4wNC4wNS4wMy4xMSAwIC4wNy0uMDUuMWwtMSAuODZxLS4wNi4wMy0uMTIuMDN0LS4xLS4wNnEtLjQyLS40OC0xLS43Ni0uNTYtLjMtMS4yMi0uMjgtLjYuMDEtMS4xMy4yNy0uNTQuMjQtLjkzLjY3LS40LjQyLS42Mi45OC0uMjMuNTYtLjIzIDEuMiAwIC42My4yNCAxLjE4LjI0LjU2LjY1Ljk4LjQuNDIuOTQuNjYuNTMuMjMgMS4xNC4yMy42My0uMDEgMS4yLS4zLjU1LS4yNy45Ni0uNzUuMDQtLjA1LjEtLjA1LjA2LS4wMi4xMS4wM2wxIC44NnEuMDYuMDMuMDYuMS4wMS4wNi0uMDMuMTEtLjY0LjczLTEuNTMgMS4xNC0uOS40MS0xLjk1LjQtLjk1IDAtMS43OS0uMzYtLjgyLS4zNy0xLjQzLS45OS0uNjEtLjYzLS45NS0xLjQ4LS4zNS0uODUtLjM1LTEuODN6IiBzdHlsZT0iLWlua3NjYXBlLWZvbnQtc3BlY2lmaWNhdGlvbjpWQUxPUkFOVDt0ZXh0LWFsaWduOmNlbnRlciIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTU5LjY0IC0yMTcuNDIpIi8+PHBhdGggZD0iTTY2LjIxIDIyMS4zNWgxLjNjLjEgMCAuMTYuMDYuMTYuMTd2MS4zOGMwIC4xMS0uMDUuMTctLjE2LjE3aC0xLjNjLS4xIDAtLjE2LS4wNi0uMTYtLjE3di0xLjM4YzAtLjExLjA1LS4xNy4xNi0uMTd6IiBsZXR0ZXItc3BhY2luZz0iLTMuMTIiIHN0eWxlPSItaW5rc2NhcGUtZm9udC1zcGVjaWZpY2F0aW9uOlZBTE9SQU5UO3RleHQtYWxpZ246Y2VudGVyIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtNTkuNjQgLTIxNy40MikiLz48L2c+PC9zdmc+&logoColor=white&labelColor=white)](https://github.com/a-sit-plus/vck)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-brightgreen.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)
[![Kotlin](https://img.shields.io/badge/kotlin-multiplatform--mobile-orange.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
![Java](https://img.shields.io/badge/java-17-blue.svg?logo=OPENJDK)
[![Maven Central](https://img.shields.io/maven-central/v/at.asitplus.wallet/mobiledrivinglicence)](https://mvnrepository.com/artifact/at.asitplus.wallet/mobiledrivinglicence/)

Expand Down Expand Up @@ -50,6 +50,10 @@ These attributes are implemented:

## Changelog

Release 1.1.0:
- Proper deserialization handling
- Update to VC-K 5.0.0

Release 1.0.3:
- Rename `Initializer.initWithVck` to `Initializer.initWithVCK`

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("at.asitplus.gradle.conventions") version "2.0.0+20240725"
id("at.asitplus.gradle.conventions") version "2.0.20+20240920"
}

val artifactVersion: String by extra
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.stability.nowarn=true
kotlin.native.ignoreDisabledTargets=true

artifactVersion = 1.0.3
artifactVersion = 1.1.0
jdk.version=17
2 changes: 1 addition & 1 deletion mobiledrivinglicence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api("at.asitplus.wallet:vck:4.1.0")
api("at.asitplus.wallet:vck:5.0.0")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package at.asitplus.wallet.mdl

import at.asitplus.wallet.lib.ItemValueDecoder
import at.asitplus.wallet.lib.ItemValueEncoder
import at.asitplus.wallet.lib.JsonValueEncoder
import at.asitplus.wallet.lib.LibraryInitializer
import at.asitplus.wallet.lib.SerializerLookup
import at.asitplus.wallet.lib.data.jsonSerializer
import at.asitplus.wallet.lib.data.vckJsonSerializer
import kotlinx.datetime.LocalDate
import kotlinx.serialization.builtins.ArraySerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.CompositeEncoder
import kotlinx.serialization.builtins.ByteArraySerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.encodeToJsonElement

object Initializer {
Expand All @@ -21,58 +19,32 @@ object Initializer {
}

/**
* This has to be called first, before anything first, to load the
* relevant classes of this library into the base implementations of VC-K
* This has to be called first, before anything, to load the
* relevant classes' serializer's of this library into the base implementations of VC-K
*/
fun initWithVCK() {
LibraryInitializer.registerExtensionLibrary(
credentialScheme = MobileDrivingLicenceScheme,
serializerLookup = serializerLookup(),
itemValueEncoder = itemValueEncoder(),
itemValueDecoder = itemValueDecoder(),
jsonValueEncoder = jsonValueEncoder()
)
}

private fun serializerLookup(): SerializerLookup = {
if (it is Array<*>) ArraySerializer(DrivingPrivilege.serializer()) else null
}

private fun itemValueEncoder(): ItemValueEncoder = { descriptor, index, compositeEncoder, value ->
if (value is Array<*> && value.isNotEmpty() && value.all { it is DrivingPrivilege }) {
true.also {
encodeArrayOfDrivingPrivileges(compositeEncoder, descriptor, index, value)
}
} else {
false
}
}

@Suppress("UNCHECKED_CAST")
private fun encodeArrayOfDrivingPrivileges(
compositeEncoder: CompositeEncoder,
descriptor: SerialDescriptor,
index: Int,
value: Any
) {
compositeEncoder.encodeSerializableElement(
descriptor,
index,
ArraySerializer(DrivingPrivilege.serializer()),
value as Array<DrivingPrivilege>
)
}

private fun itemValueDecoder(): ItemValueDecoder = { descriptor, index, compositeDecoder ->
compositeDecoder.decodeSerializableElement(
descriptor,
index,
ArraySerializer(DrivingPrivilege.serializer())
jsonValueEncoder = jsonValueEncoder(),
itemValueSerializerMap = mapOf(
MobileDrivingLicenceDataElements.BIRTH_DATE to LocalDate.serializer(),
MobileDrivingLicenceDataElements.ISSUE_DATE to LocalDate.serializer(),
MobileDrivingLicenceDataElements.EXPIRY_DATE to LocalDate.serializer(),
MobileDrivingLicenceDataElements.PORTRAIT to ByteArraySerializer(),
MobileDrivingLicenceDataElements.DRIVING_PRIVILEGES to ArraySerializer(DrivingPrivilege.serializer()),
MobileDrivingLicenceDataElements.SEX to IsoSexEnumSerializer,
MobileDrivingLicenceDataElements.HEIGHT to UInt.serializer(),
MobileDrivingLicenceDataElements.WEIGHT to UInt.serializer(),
MobileDrivingLicenceDataElements.PORTRAIT_CAPTURE_DATE to LocalDate.serializer(),
MobileDrivingLicenceDataElements.AGE_IN_YEARS to UInt.serializer(),
MobileDrivingLicenceDataElements.AGE_BIRTH_YEAR to UInt.serializer(),
MobileDrivingLicenceDataElements.SIGNATURE_USUAL_MARK to ByteArraySerializer(),
)
)
}

private fun jsonValueEncoder(): JsonValueEncoder = {
if (it is DrivingPrivilege) jsonSerializer.encodeToJsonElement(it) else null
if (it is DrivingPrivilege) vckJsonSerializer.encodeToJsonElement(it) else null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ data class MobileDrivingLicence(
/** Date when mDL expires. */
@SerialName(EXPIRY_DATE)
val expiryDate: LocalDate,

/** Alpha-2 country code, as defined in ISO 3166-1, of the issuing authority's country or territory. */
@SerialName(ISSUING_COUNTRY)
val issuingCountry: String? = null,

Expand All @@ -90,7 +88,7 @@ data class MobileDrivingLicence(

/** Driving privileges of the mDL holder. */
@SerialName(DRIVING_PRIVILEGES)
val drivingPrivileges: List<DrivingPrivilege>,
val drivingPrivileges: Array<DrivingPrivilege>,

/** Distinguishing sign of the issuing country according to ISO/IEC 18013-1:2018, Annex F. */
@SerialName(UN_DISTINGUISHING_SIGN)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package at.asitplus.wallet.mdl

import at.asitplus.KmmResult.Companion.wrap
import at.asitplus.wallet.lib.data.InstantLongSerializer
import at.asitplus.signum.indispensable.cosef.InstantLongSerializer
import at.asitplus.wallet.lib.data.NullableInstantLongSerializer
import at.asitplus.wallet.lib.data.jsonSerializer
import at.asitplus.wallet.lib.data.vckJsonSerializer
import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -27,11 +27,11 @@ data class MobileDrivingLicenceJws(
val expiration: Instant?,
) {

fun serialize() = jsonSerializer.encodeToString(this)
fun serialize() = vckJsonSerializer.encodeToString(this)

companion object {
fun deserialize(it: String) = kotlin.runCatching {
jsonSerializer.decodeFromString<MobileDrivingLicenceJws>(it)
vckJsonSerializer.decodeFromString<MobileDrivingLicenceJws>(it)
}.wrap()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package at.asitplus.wallet.mdl

import at.asitplus.KmmResult.Companion.wrap
import at.asitplus.wallet.lib.data.jsonSerializer
import at.asitplus.wallet.lib.data.vckJsonSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
Expand All @@ -15,11 +15,11 @@ data class MobileDrivingLicenceJwsNamespace(
val mdl: MobileDrivingLicence,
) {

fun serialize() = jsonSerializer.encodeToString(this)
fun serialize() = vckJsonSerializer.encodeToString(this)

companion object {
fun deserialize(it: String) = kotlin.runCatching {
jsonSerializer.decodeFromString<MobileDrivingLicenceJwsNamespace>(it)
vckJsonSerializer.decodeFromString<MobileDrivingLicenceJwsNamespace>(it)
}.wrap()
}

Expand Down
Loading
Loading