ehn-dcc-development / hcert-kotlin

Kotlin multiplatform implementation of the HCERT/DCC specification
Apache License 2.0
25 stars 25 forks source link

Empty "dr" field #48

Closed Alival-IT closed 3 years ago

Alival-IT commented 3 years ago

https://github.com/eu-digital-green-certificates/dcc-quality-assurance/blob/main/SpecialCaseHandling.md https://github.com/eu-digital-green-certificates/dcc-quality-assurance/blob/main/NL/1.3.0/specialcases/TEST_EMPTY_DR_FIELD.png

this one is not working due to: QR Code contains Version 1.3 Schema, but field "dr" is empty string and as optional in the Test QR Code

the quick fix might be

object InstantParser {
    fun parseInstant(decoder: Decoder): Instant {
        val value = decoder.decodeString()
        val fixOffset = value.replace(Regex("\\+(\\d{2})(\\d{2})")) { "+${it.groupValues[1]}:${it.groupValues[2]}" }
        val fixZulu = if (fixOffset.contains('Z') || fixOffset.contains("+")) fixOffset else fixOffset + 'Z'
        return Instant.parse(fixZulu)
    }
}

object LenientInstantParser : KSerializer<Instant> {

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

    override fun deserialize(decoder: Decoder): Instant {
        return InstantParser.parseInstant(decoder)
    }

    override fun serialize(encoder: Encoder, value: Instant) {
        encoder.encodeString(value.toString())
    }
}

object NullableLenientInstantParser : KSerializer<Instant?> {

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

    override fun deserialize(decoder: Decoder): Instant? {
        return try {
            InstantParser.parseInstant(decoder)
        } catch (e: Exception) {
            e.printStackTrace()
            null
        }
    }

    override fun serialize(encoder: Encoder, value: Instant?) {
        encoder.encodeString(value.toString())
    }
}

but then there is an action:

Verifiers should remove all date format checks from date-time values/dates

@nodh