1/****************************************************************************
2**
3** Copyright (C) 2018 Intel Corporation.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCBORCOMMON_H
41#define QCBORCOMMON_H
42
43#include <QtCore/qobjectdefs.h>
44#include <QtCore/qmetatype.h>
45#include <QtCore/qdebug.h>
46
47#if 0
48#pragma qt_class(QtCborCommon)
49#endif
50
51/* X11 headers use these values too, but as defines */
52#if defined(False) && defined(True)
53# define QT_X11_DEFINES_FOUND 1
54# undef True
55# undef False
56#endif
57
58QT_BEGIN_NAMESPACE
59
60enum class QCborSimpleType : quint8 {
61 False = 20,
62 True = 21,
63 Null = 22,
64 Undefined = 23
65};
66
67enum class QCborTag : quint64 {};
68enum class QCborKnownTags {
69 DateTimeString = 0,
70 UnixTime_t = 1,
71 PositiveBignum = 2,
72 NegativeBignum = 3,
73 Decimal = 4,
74 Bigfloat = 5,
75 COSE_Encrypt0 = 16,
76 COSE_Mac0 = 17,
77 COSE_Sign1 = 18,
78 ExpectedBase64url = 21,
79 ExpectedBase64 = 22,
80 ExpectedBase16 = 23,
81 EncodedCbor = 24,
82 Url = 32,
83 Base64url = 33,
84 Base64 = 34,
85 RegularExpression = 35,
86 MimeMessage = 36,
87 Uuid = 37,
88 COSE_Encrypt = 96,
89 COSE_Mac = 97,
90 COSE_Sign = 98,
91 Signature = 55799
92};
93
94inline bool operator==(QCborTag t, QCborKnownTags kt) { return quint64(t) == quint64(kt); }
95inline bool operator==(QCborKnownTags kt, QCborTag t) { return quint64(t) == quint64(kt); }
96inline bool operator!=(QCborTag t, QCborKnownTags kt) { return quint64(t) != quint64(kt); }
97inline bool operator!=(QCborKnownTags kt, QCborTag t) { return quint64(t) != quint64(kt); }
98
99struct Q_CORE_EXPORT QCborError
100{
101 Q_GADGET
102public:
103 enum Code : int {
104 UnknownError = 1,
105 AdvancePastEnd = 3,
106 InputOutputError = 4,
107 GarbageAtEnd = 256,
108 EndOfFile,
109 UnexpectedBreak,
110 UnknownType,
111 IllegalType,
112 IllegalNumber,
113 IllegalSimpleType,
114
115 InvalidUtf8String = 516,
116
117 DataTooLarge = 1024,
118 NestingTooDeep,
119 UnsupportedType,
120
121 NoError = 0
122 };
123 Q_ENUM(Code)
124
125 Code c;
126 operator Code() const { return c; }
127 QString toString() const;
128};
129
130#if !defined(QT_NO_DEBUG_STREAM)
131Q_CORE_EXPORT QDebug operator<<(QDebug, QCborSimpleType st);
132Q_CORE_EXPORT QDebug operator<<(QDebug, QCborKnownTags tg);
133Q_CORE_EXPORT QDebug operator<<(QDebug, QCborTag tg);
134#endif
135
136#if !defined(QT_NO_DEBUG_STREAM)
137QDataStream &operator<<(QDataStream &ds, QCborSimpleType st);
138QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st);
139#endif
140
141inline uint qHash(QCborSimpleType tag, uint seed = 0)
142{
143 return qHash(quint8(tag), seed);
144}
145
146inline uint qHash(QCborTag tag, uint seed = 0)
147{
148 return qHash(quint64(tag), seed);
149}
150
151QT_END_NAMESPACE
152
153Q_DECLARE_METATYPE(QCborTag)
154
155// To avoid changing namespace we need to reinstate defines, even though our .cpp
156// will then have to remove them again.
157#if defined(QT_X11_DEFINES_FOUND)
158# define True 1
159# define False 0
160#endif
161
162#endif // QCBORSTREAM_H
163