KHealthCertificate

health-certificate-decode.cpp
1 /*
2  * SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3  * SPDX-License-Identifier: LGPL-2.0-or-later
4  */
5 
6 #include <KHealthCertificate/KHealthCertificateParser>
7 #include <KHealthCertificate/KRecoveryCertificate>
8 #include <KHealthCertificate/KTestCertificate>
9 #include <KHealthCertificate/KVaccinationCertificate>
10 
11 #include <QDebug>
12 #include <QFile>
13 #include <QMetaProperty>
14 #include <QVariant>
15 
16 #include <iostream>
17 
18 static void dumpGadget(const QVariant &gadget)
19 {
20  const auto mo = QMetaType(gadget.userType()).metaObject();
21  if (!mo) {
22  return;
23  }
24 
25  for (auto i = 0; i < mo->propertyCount(); ++i) {
26  const auto prop = mo->property(i);
27  if (!prop.isStored()) {
28  continue;
29  }
30  const auto value = prop.readOnGadget(gadget.constData());
31  std::cout << " " << prop.name() << ": " << qPrintable(value.toString()) << std::endl;
32  }
33 }
34 
35 int main(int argc, char **argv)
36 {
37  // TODO cli arg parsing
38 
39  QFile in;
40  in.open(stdin, QFile::ReadOnly);
41 
42  const auto cert = KHealthCertificateParser::parse(in.readAll());
43  if (cert.isNull()) {
44  std::cout << "unable to parse input" << std::endl;
45  return 1;
46  }
47 
48  if (cert.userType() == qMetaTypeId<KVaccinationCertificate>()) {
49  std::cout << "Vaccination certificate:" << std::endl;
50  } else if (cert.userType() == qMetaTypeId<KTestCertificate>()) {
51  std::cout << "Test certificate:" << std::endl;
52  } else if (cert.userType() == qMetaTypeId<KRecoveryCertificate>()) {
53  std::cout << "Recovery certificate:" << std::endl;
54  }
55  dumpGadget(cert);
56 
57  return 0;
58 }
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Parse a single digital health certificate.
QByteArray readAll()
virtual bool open(QIODevice::OpenMode mode) override
int userType() const 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.