From 1dde65920ff01c9482b4df280c6198834e009115 Mon Sep 17 00:00:00 2001 From: norangebit Date: Thu, 25 Jun 2020 11:04:55 +0200 Subject: [PATCH] Add generateContactNumbers --- .../it/unisannio/assd/tkn/report/Report.kt | 8 +++++ .../kotlin/it/unisannio/assd/tkn/TestConst.kt | 3 ++ .../unisannio/assd/tkn/report/ReportTest.kt | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/main/kotlin/it/unisannio/assd/tkn/report/Report.kt b/src/main/kotlin/it/unisannio/assd/tkn/report/Report.kt index bf3f886..27abfcf 100644 --- a/src/main/kotlin/it/unisannio/assd/tkn/report/Report.kt +++ b/src/main/kotlin/it/unisannio/assd/tkn/report/Report.kt @@ -4,6 +4,7 @@ import it.unisannio.assd.tkn.Const import it.unisannio.assd.tkn.key.ReportAuthorizationKey import it.unisannio.assd.tkn.key.ReportVerificationKey import it.unisannio.assd.tkn.key.TemporaryContactKey +import it.unisannio.assd.tkn.key.TemporaryContactNumber import it.unisannio.assd.tkn.read import it.unisannio.assd.tkn.toHexString import java.nio.ByteBuffer @@ -20,6 +21,13 @@ class Report private constructor(private val report: ByteArray) { rak ) + fun generateContactNumbers(): List = reportData.rvk + .contactNumbersBetween( + reportData.tck, + reportData.from, + reportData.until + ) + fun getVerificationKey(): ReportVerificationKey = reportData.rvk fun toReportData(): ReportData = reportData diff --git a/src/test/kotlin/it/unisannio/assd/tkn/TestConst.kt b/src/test/kotlin/it/unisannio/assd/tkn/TestConst.kt index 06b497a..b0ad8b7 100644 --- a/src/test/kotlin/it/unisannio/assd/tkn/TestConst.kt +++ b/src/test/kotlin/it/unisannio/assd/tkn/TestConst.kt @@ -17,4 +17,7 @@ object TestConst { "bec8be3a8add45ce77897b1e7cb1906b5cff1097d3cb142fd9d002000a00000c73796d70746f6d2064617461" const val REPORT_SIGN = "31078ec5367b67a8c793b740626d81ba904789363137b5a313419c0f50b180d8226ecc984bf073ff" + "89cbd9c88fea06bda1f0f368b0e7e88bbe68f15574482904" + const val REPORT_MEMO = "symptom data" + const val REPORT_FROM = 2.toShort() + const val REPORT_UNTIL = 10.toShort() } diff --git a/src/test/kotlin/it/unisannio/assd/tkn/report/ReportTest.kt b/src/test/kotlin/it/unisannio/assd/tkn/report/ReportTest.kt index ca33948..4bef170 100644 --- a/src/test/kotlin/it/unisannio/assd/tkn/report/ReportTest.kt +++ b/src/test/kotlin/it/unisannio/assd/tkn/report/ReportTest.kt @@ -29,6 +29,41 @@ class ReportTest { .toHexString() `should be equal to` TestConst.REPORT_SIGN } + @Test + fun generateContactNumbers() { + val report = Report.readReportFromByteArray( + TestConst.REPORT_MESSAGE.toHexByteArray() + ) + + report.generateContactNumbers() + .take(2).map { it.toHexString() } `should be equal to` listOf( + TestConst.TCN_2, + TestConst.TCN_3 + ) + + } + + @Test + fun toReportData() { + val report = Report.readReportFromByteArray( + TestConst.REPORT_MESSAGE.toHexByteArray() + ) + + val reportData = report.toReportData() + + reportData.rvk + .toHexString() `should be equal to` TestConst.PUBLIC_KEY_STRING_HEX + + reportData.tck + .toHexString() `should be equal to` TestConst.TCK_1 + + reportData.from `should be equal to` TestConst.REPORT_FROM + + reportData.until `should be equal to` TestConst.REPORT_UNTIL + + reportData.memo `should be equal to` TestConst.REPORT_MEMO + } + @Test fun getVerificationKey() { val report = Report.readReportFromByteArray(