diff --git a/decoder/src/main/java/dgca/verifier/app/decoder/cbor/CborService.kt b/decoder/src/main/java/dgca/verifier/app/decoder/cbor/CborService.kt index 0c2b8bb..4f54c8f 100644 --- a/decoder/src/main/java/dgca/verifier/app/decoder/cbor/CborService.kt +++ b/decoder/src/main/java/dgca/verifier/app/decoder/cbor/CborService.kt @@ -51,4 +51,6 @@ interface CborService { input: ByteArray, verificationResult: VerificationResult ): GreenCertificateData? + + fun getPayload(input: ByteArray): ByteArray? } \ No newline at end of file diff --git a/decoder/src/main/java/dgca/verifier/app/decoder/cbor/DefaultCborService.kt b/decoder/src/main/java/dgca/verifier/app/decoder/cbor/DefaultCborService.kt index 7c1dd9d..6875514 100644 --- a/decoder/src/main/java/dgca/verifier/app/decoder/cbor/DefaultCborService.kt +++ b/decoder/src/main/java/dgca/verifier/app/decoder/cbor/DefaultCborService.kt @@ -32,16 +32,17 @@ import java.time.ZoneOffset /** * Decodes input as a CBOR structure */ -class DefaultCborService(private val greenCertificateMapper: GreenCertificateMapper = DefaultGreenCertificateMapper()) : CborService { +class DefaultCborService(private val greenCertificateMapper: GreenCertificateMapper = DefaultGreenCertificateMapper()) : + CborService { override fun decode( - input: ByteArray, - verificationResult: VerificationResult + input: ByteArray, + verificationResult: VerificationResult ): GreenCertificate? = decodeData(input, verificationResult)?.greenCertificate override fun decodeData( - input: ByteArray, - verificationResult: VerificationResult + input: ByteArray, + verificationResult: VerificationResult ): GreenCertificateData? { verificationResult.cborDecoded = false return try { @@ -60,10 +61,26 @@ class DefaultCborService(private val greenCertificateMapper: GreenCertificateMap val cborObject = hcert[CBORObject.FromObject(1)] val greenCertificate: GreenCertificate = greenCertificateMapper.readValue(cborObject) - .also { verificationResult.cborDecoded = true } - GreenCertificateData(issuingCountry, cborObject.ToJSONString(), greenCertificate, issuedAt.atZone(ZoneOffset.UTC), expirationTime.atZone(ZoneOffset.UTC)) + .also { verificationResult.cborDecoded = true } + GreenCertificateData( + issuingCountry, + cborObject.ToJSONString(), + greenCertificate, + issuedAt.atZone(ZoneOffset.UTC), + expirationTime.atZone(ZoneOffset.UTC) + ) } catch (e: Throwable) { null } } + + override fun getPayload(input: ByteArray): ByteArray? { + return try { + val map = CBORObject.DecodeFromBytes(input) + val hcert = map[CwtHeaderKeys.HCERT.asCBOR()] + hcert[CBORObject.FromObject(1)].EncodeToBytes() + } catch (ex: Exception) { + null + } + } } \ No newline at end of file