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