Skip to content

Commit

Permalink
- add vaccination date check to verification result; (eu-digital-gree…
Browse files Browse the repository at this point in the history
  • Loading branch information
MykhailoNester authored Sep 17, 2021
1 parent 1558ee9 commit 11429c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
package dgca.verifier.app.decoder.model

import com.fasterxml.jackson.annotation.JsonProperty
import org.joda.time.DateTime
import java.io.Serializable
import java.time.*
import java.time.format.DateTimeFormatter

data class RecoveryStatement(

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
package dgca.verifier.app.decoder.model

import com.fasterxml.jackson.annotation.JsonProperty
import org.joda.time.DateTime
import java.io.Serializable
import java.time.OffsetDateTime

data class Vaccination(

Expand Down Expand Up @@ -57,4 +59,12 @@ data class Vaccination(
@JsonProperty("ci")
val certificateIdentifier: String

) : Serializable
) : Serializable {

fun isDateInThePast(): Boolean =
try {
DateTime.parse(dateOfVaccination).millis < OffsetDateTime.now().toEpochSecond() * 1000
} catch (ex: Exception) {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ data class VerificationResult(
var isIssuedTimeCorrect: Boolean = false,
var isNotExpired: Boolean = false,
var rulesValidationFailed: Boolean = false,
var vaccinationVerification: VaccinationVerificationResult? = null,
var testVerification: TestVerificationResult? = null,
var recoveryVerification: RecoveryVerificationResult? = null
) {

fun isValid(): Boolean {
val isVaccinationValid = vaccinationVerification?.isVaccinationValid() ?: true
val isTestValid = testVerification?.isTestValid() ?: true
val isRecoveryValid = recoveryVerification?.isRecoveryValid() ?: true;
val isRecoveryValid = recoveryVerification?.isRecoveryValid() ?: true
return base45Decoded && zlibDecoded && coseVerified && cborDecoded && isSchemaValid && isTestValid &&
isIssuedTimeCorrect && isNotExpired && !rulesValidationFailed && isRecoveryValid
isIssuedTimeCorrect && isNotExpired && !rulesValidationFailed && isRecoveryValid && isVaccinationValid
}

/**
Expand Down Expand Up @@ -73,6 +75,15 @@ data class VerificationResult(
recoveryVerification!!.isNotValidSoFar
}

/**
* Checks if vaccination date is valid.
*/
fun isVaccinationDateInTheFuture(): Boolean = if (vaccinationVerification == null) {
false
} else {
!vaccinationVerification!!.isVaccinationDateInThePast
}

override fun toString(): String {
return "VerificationResult: \n" +
"base45Decoded: $base45Decoded \n" +
Expand All @@ -84,6 +95,10 @@ data class VerificationResult(
}
}

data class VaccinationVerificationResult(val isVaccinationDateInThePast: Boolean) {
fun isVaccinationValid(): Boolean = isVaccinationDateInThePast
}

data class TestVerificationResult(val isTestResultNegative: Boolean, val isTestDateInThePast: Boolean) {
fun isTestValid(): Boolean = isTestResultNegative && isTestDateInThePast
}
Expand Down

0 comments on commit 11429c0

Please sign in to comment.