File indexing completed on 2024-11-24 04:44:41

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 #include "ktestcertificate.h"
0007 #include "khealthcertificatetypes_p.h"
0008 
0009 class KTestCertificatePrivate : public QSharedData
0010 {
0011 public:
0012     QString name;
0013     QDate dateOfBirth;
0014     QDate date;
0015     QString disease;
0016     QString testType;
0017     QString testName;
0018     QUrl testUrl;
0019     KTestCertificate::Result result = KTestCertificate::Unknown;
0020     QString resultString;
0021     QString testCenter;
0022     QString country;
0023     QString certificateIssuer;
0024     QString certificateId;
0025     QDateTime certificateIssueDate;
0026     QDateTime certificateExpiryDate;
0027     QByteArray rawData;
0028     KHealthCertificate::SignatureValidation signatureState = KHealthCertificate::UnknownSignature;
0029 };
0030 
0031 KHEALTHCERTIFICATE_MAKE_GADGET(Test)
0032 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, name, setName)
0033 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QDate, dateOfBirth, setDateOfBirth)
0034 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QDate, date, setDate)
0035 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, disease, setDisease)
0036 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, testType, setTestType)
0037 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, testName, setTestName)
0038 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QUrl, testUrl, setTestUrl)
0039 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, KTestCertificate::Result, result, setResult)
0040 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, resultString, setResultString)
0041 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, testCenter, setTestCenter)
0042 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, country, setCountry)
0043 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, certificateIssuer, setCertificateIssuer)
0044 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QString, certificateId, setCertificateId)
0045 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QDateTime, certificateIssueDate, setCertificateIssueDate)
0046 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QDateTime, certificateExpiryDate, setCertificateExpiryDate)
0047 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, QByteArray, rawData, setRawData)
0048 KHEALTHCERTIFICATE_MAKE_PROPERTY(Test, KHealthCertificate::SignatureValidation, signatureState, setSignatureState)
0049 
0050 KHealthCertificate::CertificateValidation KTestCertificate::validationState() const
0051 {
0052     if (d->certificateIssueDate > QDateTime::currentDateTime() || (d->certificateExpiryDate.isValid() && d->certificateExpiryDate < QDateTime::currentDateTime())) {
0053         return KHealthCertificate::Invalid;
0054     }
0055     if (d->signatureState == KHealthCertificate::InvalidSignature || d->result == Unknown) {
0056         return KHealthCertificate::Invalid;
0057     }
0058 
0059     if (d->result == Positive || !isCurrent()) {
0060         return KHealthCertificate::Partial;
0061     }
0062     if (d->signatureState == KHealthCertificate::UnknownSignature) {
0063         return KHealthCertificate::Partial;
0064     }
0065 
0066     return KHealthCertificate::Valid;
0067 }
0068 
0069 bool KTestCertificate::isCurrent() const
0070 {
0071     return d->date.addDays(2) >= QDate::currentDate();
0072 }
0073 
0074 #include "moc_ktestcertificate.moc"