@@ -32,16 +32,17 @@ import java.time.ZoneOffset
3232/* *
3333 * Decodes input as a CBOR structure
3434 */
35- class DefaultCborService (private val greenCertificateMapper : GreenCertificateMapper = DefaultGreenCertificateMapper ()) : CborService {
35+ class DefaultCborService (private val greenCertificateMapper : GreenCertificateMapper = DefaultGreenCertificateMapper ()) :
36+ CborService {
3637
3738 override fun decode (
38- input : ByteArray ,
39- verificationResult : VerificationResult
39+ input : ByteArray ,
40+ verificationResult : VerificationResult
4041 ): GreenCertificate ? = decodeData(input, verificationResult)?.greenCertificate
4142
4243 override fun decodeData (
43- input : ByteArray ,
44- verificationResult : VerificationResult
44+ input : ByteArray ,
45+ verificationResult : VerificationResult
4546 ): GreenCertificateData ? {
4647 verificationResult.cborDecoded = false
4748 return try {
@@ -60,10 +61,26 @@ class DefaultCborService(private val greenCertificateMapper: GreenCertificateMap
6061 val cborObject = hcert[CBORObject .FromObject (1 )]
6162
6263 val greenCertificate: GreenCertificate = greenCertificateMapper.readValue(cborObject)
63- .also { verificationResult.cborDecoded = true }
64- GreenCertificateData (issuingCountry, cborObject.ToJSONString (), greenCertificate, issuedAt.atZone(ZoneOffset .UTC ), expirationTime.atZone(ZoneOffset .UTC ))
64+ .also { verificationResult.cborDecoded = true }
65+ GreenCertificateData (
66+ issuingCountry,
67+ cborObject.ToJSONString (),
68+ greenCertificate,
69+ issuedAt.atZone(ZoneOffset .UTC ),
70+ expirationTime.atZone(ZoneOffset .UTC )
71+ )
6572 } catch (e: Throwable ) {
6673 null
6774 }
6875 }
76+
77+ override fun getPayload (input : ByteArray ): ByteArray? {
78+ return try {
79+ val map = CBORObject .DecodeFromBytes (input)
80+ val hcert = map[CwtHeaderKeys .HCERT .asCBOR()]
81+ hcert[CBORObject .FromObject (1 )].EncodeToBytes ()
82+ } catch (ex: Exception ) {
83+ null
84+ }
85+ }
6986}
0 commit comments