KHealthCertificate

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