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 | # undef True |
54 | # undef False |
55 | #endif |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | enum class QCborSimpleType : quint8 { |
60 | False = 20, |
61 | True = 21, |
62 | Null = 22, |
63 | Undefined = 23 |
64 | }; |
65 | |
66 | enum class QCborTag : quint64 {}; |
67 | enum class QCborKnownTags { |
68 | DateTimeString = 0, |
69 | UnixTime_t = 1, |
70 | PositiveBignum = 2, |
71 | NegativeBignum = 3, |
72 | Decimal = 4, |
73 | Bigfloat = 5, |
74 | COSE_Encrypt0 = 16, |
75 | COSE_Mac0 = 17, |
76 | COSE_Sign1 = 18, |
77 | ExpectedBase64url = 21, |
78 | ExpectedBase64 = 22, |
79 | ExpectedBase16 = 23, |
80 | EncodedCbor = 24, |
81 | Url = 32, |
82 | Base64url = 33, |
83 | Base64 = 34, |
84 | RegularExpression = 35, |
85 | MimeMessage = 36, |
86 | Uuid = 37, |
87 | COSE_Encrypt = 96, |
88 | COSE_Mac = 97, |
89 | COSE_Sign = 98, |
90 | Signature = 55799 |
91 | }; |
92 | |
93 | inline bool operator==(QCborTag t, QCborKnownTags kt) { return quint64(t) == quint64(kt); } |
94 | inline bool operator==(QCborKnownTags kt, QCborTag t) { return quint64(t) == quint64(kt); } |
95 | inline bool operator!=(QCborTag t, QCborKnownTags kt) { return quint64(t) != quint64(kt); } |
96 | inline bool operator!=(QCborKnownTags kt, QCborTag t) { return quint64(t) != quint64(kt); } |
97 | |
98 | struct Q_CORE_EXPORT QCborError |
99 | { |
100 | Q_GADGET |
101 | public: |
102 | enum Code : int { |
103 | UnknownError = 1, |
104 | AdvancePastEnd = 3, |
105 | InputOutputError = 4, |
106 | GarbageAtEnd = 256, |
107 | EndOfFile, |
108 | UnexpectedBreak, |
109 | UnknownType, |
110 | IllegalType, |
111 | IllegalNumber, |
112 | IllegalSimpleType, |
113 | |
114 | InvalidUtf8String = 516, |
115 | |
116 | DataTooLarge = 1024, |
117 | NestingTooDeep, |
118 | UnsupportedType, |
119 | |
120 | NoError = 0 |
121 | }; |
122 | Q_ENUM(Code) |
123 | |
124 | Code c; |
125 | operator Code() const { return c; } |
126 | QString toString() const; |
127 | }; |
128 | |
129 | #if !defined(QT_NO_DEBUG_STREAM) |
130 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborSimpleType st); |
131 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborKnownTags tg); |
132 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborTag tg); |
133 | #endif |
134 | |
135 | #if !defined(QT_NO_DEBUG_STREAM) |
136 | QDataStream &operator<<(QDataStream &ds, QCborSimpleType st); |
137 | QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st); |
138 | #endif |
139 | |
140 | inline uint qHash(QCborSimpleType tag, uint seed = 0) |
141 | { |
142 | return qHash(quint8(tag), seed); |
143 | } |
144 | |
145 | inline uint qHash(QCborTag tag, uint seed = 0) |
146 | { |
147 | return qHash(quint64(tag), seed); |
148 | } |
149 | |
150 | enum class QCborNegativeInteger : quint64 {}; |
151 | |
152 | QT_END_NAMESPACE |
153 | |
154 | Q_DECLARE_METATYPE(QCborTag) |
155 | |
156 | // To avoid changing namespace we need to reinstate defines, even though our .cpp |
157 | // will then have to remove them again. |
158 | #if defined(QT_X11_DEFINES_FOUND) |
159 | # define True 1 |
160 | # define False 0 |
161 | #endif |
162 | |
163 | #endif // QCBORSTREAM_H |
164 | |