1 | // Copyright (C) 2018 Intel Corporation. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QCBORCOMMON_H |
5 | #define QCBORCOMMON_H |
6 | |
7 | #include <QtCore/qobjectdefs.h> |
8 | #include <QtCore/qmetatype.h> |
9 | #include <QtCore/qdebug.h> |
10 | |
11 | #if 0 |
12 | #pragma qt_class(QtCborCommon) |
13 | #endif |
14 | |
15 | /* X11 headers use these values too, but as defines */ |
16 | #if defined(False) && defined(True) |
17 | # undef True |
18 | # undef False |
19 | #endif |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | enum class QCborSimpleType : quint8 { |
24 | False = 20, |
25 | True = 21, |
26 | Null = 22, |
27 | Undefined = 23 |
28 | }; |
29 | |
30 | enum class QCborTag : quint64 {}; |
31 | enum class QCborKnownTags { |
32 | DateTimeString = 0, |
33 | UnixTime_t = 1, |
34 | PositiveBignum = 2, |
35 | NegativeBignum = 3, |
36 | Decimal = 4, |
37 | Bigfloat = 5, |
38 | COSE_Encrypt0 = 16, |
39 | COSE_Mac0 = 17, |
40 | COSE_Sign1 = 18, |
41 | ExpectedBase64url = 21, |
42 | ExpectedBase64 = 22, |
43 | ExpectedBase16 = 23, |
44 | EncodedCbor = 24, |
45 | Url = 32, |
46 | Base64url = 33, |
47 | Base64 = 34, |
48 | RegularExpression = 35, |
49 | MimeMessage = 36, |
50 | Uuid = 37, |
51 | COSE_Encrypt = 96, |
52 | COSE_Mac = 97, |
53 | COSE_Sign = 98, |
54 | Signature = 55799 |
55 | }; |
56 | |
57 | inline bool operator==(QCborTag t, QCborKnownTags kt) { return quint64(t) == quint64(kt); } |
58 | inline bool operator==(QCborKnownTags kt, QCborTag t) { return quint64(t) == quint64(kt); } |
59 | inline bool operator!=(QCborTag t, QCborKnownTags kt) { return quint64(t) != quint64(kt); } |
60 | inline bool operator!=(QCborKnownTags kt, QCborTag t) { return quint64(t) != quint64(kt); } |
61 | |
62 | struct Q_CORE_EXPORT QCborError |
63 | { |
64 | Q_GADGET |
65 | public: |
66 | enum Code : int { |
67 | UnknownError = 1, |
68 | AdvancePastEnd = 3, |
69 | InputOutputError = 4, |
70 | GarbageAtEnd = 256, |
71 | EndOfFile, |
72 | UnexpectedBreak, |
73 | UnknownType, |
74 | IllegalType, |
75 | IllegalNumber, |
76 | IllegalSimpleType, |
77 | |
78 | InvalidUtf8String = 516, |
79 | |
80 | DataTooLarge = 1024, |
81 | NestingTooDeep, |
82 | UnsupportedType, |
83 | |
84 | NoError = 0 |
85 | }; |
86 | Q_ENUM(Code) |
87 | |
88 | Code c; |
89 | operator Code() const { return c; } |
90 | QString toString() const; |
91 | }; |
92 | |
93 | #if !defined(QT_NO_DEBUG_STREAM) |
94 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborSimpleType st); |
95 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborKnownTags tg); |
96 | Q_CORE_EXPORT QDebug operator<<(QDebug, QCborTag tg); |
97 | #endif |
98 | |
99 | #if !defined(QT_NO_DATASTREAM) |
100 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, QCborSimpleType st); |
101 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st); |
102 | #endif |
103 | |
104 | inline size_t qHash(QCborSimpleType tag, size_t seed = 0) |
105 | { |
106 | return qHash(key: quint8(tag), seed); |
107 | } |
108 | |
109 | inline size_t qHash(QCborTag tag, size_t seed = 0) |
110 | { |
111 | return qHash(key: quint64(tag), seed); |
112 | } |
113 | |
114 | enum class QCborNegativeInteger : quint64 {}; |
115 | |
116 | QT_END_NAMESPACE |
117 | |
118 | QT_DECL_METATYPE_EXTERN(QCborTag, Q_CORE_EXPORT) |
119 | |
120 | // To avoid changing namespace we need to reinstate defines, even though our .cpp |
121 | // will then have to remove them again. |
122 | #if defined(QT_X11_DEFINES_FOUND) |
123 | # define True 1 |
124 | # define False 0 |
125 | #endif |
126 | |
127 | #endif // QCBORSTREAM_H |
128 | |