KHealthCertificate

cborutils.cpp
1 /*
2  * SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
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 #include <QDebug>
11 
12 int64_t CborUtils::readInteger(QCborStreamReader &reader)
13 {
14  if (!reader.isInteger()) {
15  return {};
16  }
17  const auto result = reader.toInteger();
18  reader.next();
19  return result;
20 }
21 
22 QString CborUtils::readString(QCborStreamReader &reader)
23 {
24  if (!reader.isString()) {
25  return {};
26  }
27 
28  QString result;
29  auto r = reader.readString();
30  while (r.status == QCborStreamReader::Ok) {
31  result += r.data;
32  r = reader.readString();
33  }
34  if (r.status == QCborStreamReader::Error) {
35  qCWarning(Log) << "CBOR string read error";
36  result.clear();
37  }
38  return result;
39 }
40 
41 QByteArray CborUtils::readByteArray(QCborStreamReader &reader)
42 {
43  if (!reader.isByteArray()) {
44  return {};
45  }
46 
47  QByteArray result;
48  auto r = reader.readByteArray();
49  while (r.status == QCborStreamReader::Ok) {
50  result += r.data;
51  r = reader.readByteArray();
52  }
53 
54  if (r.status == QCborStreamReader::Error) {
55  qCWarning(Log) << "CBOR byte array read error";
56  result.clear();
57  }
58  return result;
59 }
StringResult< QByteArray > readByteArray()
qint64 toInteger() const const
void clear()
bool isString() const const
bool next(int maxRecursion)
void clear()
bool isByteArray() const const
bool isInteger() const const
StringResult< QString > readString()
char * data()
QChar * data()
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.