KHealthCertificate

cborutils.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6#include "cborutils_p.h"
7#include "logging.h"
8
9#include <QCborStreamReader>
10
11int64_t CborUtils::readInteger(QCborStreamReader &reader)
12{
13 if (!reader.isInteger()) {
14 return {};
15 }
16 const auto result = reader.toInteger();
17 reader.next();
18 return result;
19}
20
21QString CborUtils::readString(QCborStreamReader &reader)
22{
23 if (!reader.isString()) {
24 return {};
25 }
26
27 QString result;
28 auto r = reader.readString();
29 while (r.status == QCborStreamReader::Ok) {
30 result += r.data;
31 r = reader.readString();
32 }
33 if (r.status == QCborStreamReader::Error) {
34 qCWarning(Log) << "CBOR string read error";
35 result.clear();
36 }
37 return result;
38}
39
40QByteArray CborUtils::readByteArray(QCborStreamReader &reader)
41{
42 if (!reader.isByteArray()) {
43 return {};
44 }
45
46 QByteArray result;
47 auto r = reader.readByteArray();
48 while (r.status == QCborStreamReader::Ok) {
49 result += r.data;
50 r = reader.readByteArray();
51 }
52
53 if (r.status == QCborStreamReader::Error) {
54 qCWarning(Log) << "CBOR byte array read error";
55 result.clear();
56 }
57 return result;
58}
void clear()
char * data()
bool isByteArray() const const
bool isInteger() const const
bool isString() const const
bool next(int maxRecursion)
StringResult< QByteArray > readByteArray()
StringResult< QString > readString()
qint64 toInteger() const const
void clear()
QChar * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.