KHealthCertificate

khealthcertificateparser.cpp
1 /*
2  * SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3  * SPDX-License-Identifier: LGPL-2.0-or-later
4  */
5 
6 #include "khealthcertificateparser.h"
7 #include "divocparser_p.h"
8 #include "eudgcparser_p.h"
9 #include "shcparser_p.h"
10 
11 #include <KZip>
12 
13 #include <QBuffer>
14 #include <QByteArray>
15 #include <QVariant>
16 
18 {
19  EuDgcParser eudcg;
20  auto result = eudcg.parse(data);
21  if (!result.isNull()) {
22  return result;
23  }
24  result = DivocParser::parse(data);
25  if (!result.isNull()) {
26  return result;
27  }
28  result = ShcParser::parse(data);
29  if (!result.isNull()) {
30  return result;
31  }
32 
33  // ZIP unpacking (needed for Indian certificates)
34  if (data.startsWith(QByteArray("\x50\x4B\x03\x04"))) {
35  QBuffer buffer;
36  buffer.setData(data);
37  buffer.open(QIODevice::ReadOnly);
38  KZip zip(&buffer);
39  if (!zip.open(QIODevice::ReadOnly)) {
40  return {};
41  }
42  const auto entries = zip.directory()->entries();
43  for (const auto &entry : entries) {
44  if (auto f = zip.directory()->file(entry)) {
45  result = parse(f->data());
46  if (!result.isNull()) {
47  auto vac = result.value<KVaccinationCertificate>();
48  vac.setRawData(data);
49  return vac;
50  }
51  }
52  }
53 
54  }
55 
56  return {};
57 }
void setData(const QByteArray &data)
bool startsWith(const QByteArray &ba) const const
virtual bool open(QIODevice::OpenMode mode)
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Parse a single digital health certificate.
virtual bool open(QIODevice::OpenMode flags) override
A vaccination certificate.
const KArchiveDirectory * directory() const
const KArchiveFile * file(const QString &name) const
QStringList entries() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 18 2021 23:21:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.