KHealthCertificate

khealthcertificateparser.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6#include "khealthcertificateparser.h"
7#include "divoc/divocparser_p.h"
8#include "eu-dgc/eudgcparser_p.h"
9#include "icao/icaovdsparser_p.h"
10#include "nl-coronacheck/nlcoronacheckparser_p.h"
11#include "shc/shcparser_p.h"
12
13#include <KZip>
14
15#include <QBuffer>
16#include <QByteArray>
17#include <QVariant>
18
19static bool initResources()
20{
21 DivocParser::init();
22 EuDgcParser::init();
23 IcaoVdsParser::init();
24 NLCoronaCheckParser::init();
25 ShcParser::init();
26
27 return true;
28}
29
31{
32 [[maybe_unused]] static bool s_init = initResources();
33
34 EuDgcParser eudcg;
35 auto result = eudcg.parse(data);
36 if (!result.isNull()) {
37 return result;
38 }
39 result = DivocParser::parse(data);
40 if (!result.isNull()) {
41 return result;
42 }
43 result = ShcParser::parse(data);
44 if (!result.isNull()) {
45 return result;
46 }
47 result = IcaoVdsParser::parse(data);
48 if (!result.isNull()) {
49 return result;
50 }
51 result = NLCoronaCheckParser::parse(data);
52 if (!result.isNull()) {
53 return result;
54 }
55
56 // ZIP unpacking (needed for Indian certificates)
57 if (data.startsWith(QByteArray("\x50\x4B\x03\x04"))) {
58 QBuffer buffer;
59 buffer.setData(data);
61 KZip zip(&buffer);
62 if (!zip.open(QIODevice::ReadOnly)) {
63 return {};
64 }
65 const auto entries = zip.directory()->entries();
66 for (const auto &entry : entries) {
67 if (auto f = zip.directory()->file(entry)) {
68 result = parse(f->data());
69 if (!result.isNull()) {
70 auto vac = result.value<KVaccinationCertificate>();
71 vac.setRawData(data);
72 return vac;
73 }
74 }
75 }
76
77 }
78
79 return {};
80}
QStringList entries() const
const KArchiveFile * file(const QString &name) const
virtual bool open(QIODevice::OpenMode mode)
const KArchiveDirectory * directory() const
A vaccination certificate.
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Parse a single digital health certificate.
virtual bool open(OpenMode flags) override
void setData(const QByteArray &data)
bool startsWith(QByteArrayView bv) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.