| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | |
| 5 | #ifndef QSSLERROR_H |
| 6 | #define QSSLERROR_H |
| 7 | |
| 8 | #include <QtNetwork/qtnetworkglobal.h> |
| 9 | #include <QtCore/qvariant.h> |
| 10 | #include <QtNetwork/qsslcertificate.h> |
| 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | |
| 17 | #ifndef QT_NO_SSL |
| 18 | |
| 19 | #ifndef QT_NO_DEBUG_STREAM |
| 20 | class QDebug; |
| 21 | #endif |
| 22 | |
| 23 | class QSslErrorPrivate; |
| 24 | class Q_NETWORK_EXPORT QSslError |
| 25 | { |
| 26 | Q_GADGET |
| 27 | public: |
| 28 | enum SslError { |
| 29 | NoError, |
| 30 | UnableToGetIssuerCertificate, |
| 31 | UnableToDecryptCertificateSignature, |
| 32 | UnableToDecodeIssuerPublicKey, |
| 33 | CertificateSignatureFailed, |
| 34 | CertificateNotYetValid, |
| 35 | CertificateExpired, |
| 36 | InvalidNotBeforeField, |
| 37 | InvalidNotAfterField, |
| 38 | SelfSignedCertificate, |
| 39 | SelfSignedCertificateInChain, |
| 40 | UnableToGetLocalIssuerCertificate, |
| 41 | UnableToVerifyFirstCertificate, |
| 42 | CertificateRevoked, |
| 43 | InvalidCaCertificate, |
| 44 | PathLengthExceeded, |
| 45 | InvalidPurpose, |
| 46 | CertificateUntrusted, |
| 47 | CertificateRejected, |
| 48 | SubjectIssuerMismatch, // hostname mismatch? |
| 49 | AuthorityIssuerSerialNumberMismatch, |
| 50 | NoPeerCertificate, |
| 51 | HostNameMismatch, |
| 52 | NoSslSupport, |
| 53 | CertificateBlacklisted, |
| 54 | CertificateStatusUnknown, |
| 55 | OcspNoResponseFound, |
| 56 | OcspMalformedRequest, |
| 57 | OcspMalformedResponse, |
| 58 | OcspInternalError, |
| 59 | OcspTryLater, |
| 60 | OcspSigRequred, |
| 61 | OcspUnauthorized, |
| 62 | OcspResponseCannotBeTrusted, |
| 63 | OcspResponseCertIdUnknown, |
| 64 | OcspResponseExpired, |
| 65 | OcspStatusUnknown, |
| 66 | UnspecifiedError = -1 |
| 67 | }; |
| 68 | Q_ENUM(SslError) |
| 69 | |
| 70 | // RVCT compiler in debug build does not like about default values in const- |
| 71 | // So as an workaround we define all constructor overloads here explicitly |
| 72 | QSslError(); |
| 73 | explicit QSslError(SslError error); |
| 74 | QSslError(SslError error, const QSslCertificate &certificate); |
| 75 | |
| 76 | QSslError(const QSslError &other); |
| 77 | |
| 78 | void swap(QSslError &other) noexcept |
| 79 | { d.swap(u&: other.d); } |
| 80 | |
| 81 | ~QSslError(); |
| 82 | QSslError &operator=(QSslError &&other) noexcept { swap(other); return *this; } |
| 83 | QSslError &operator=(const QSslError &other); |
| 84 | bool operator==(const QSslError &other) const; |
| 85 | inline bool operator!=(const QSslError &other) const |
| 86 | { return !(*this == other); } |
| 87 | |
| 88 | SslError error() const; |
| 89 | QString errorString() const; |
| 90 | QSslCertificate certificate() const; |
| 91 | |
| 92 | private: |
| 93 | // ### Qt 7: make QSslError implicitly shared |
| 94 | std::unique_ptr<QSslErrorPrivate> d; |
| 95 | #ifndef QT_NO_DEBUG_STREAM |
| 96 | Q_NETWORK_EXPORT friend QDebug print(QDebug debug, QSslError::SslError error); |
| 97 | friend QDebug operator<<(QDebug debug, SslError error) |
| 98 | { return print(debug: std::move(debug), error); } |
| 99 | #endif |
| 100 | }; |
| 101 | Q_DECLARE_SHARED(QSslError) |
| 102 | |
| 103 | Q_NETWORK_EXPORT size_t qHash(const QSslError &key, size_t seed = 0) noexcept; |
| 104 | |
| 105 | #ifndef QT_NO_DEBUG_STREAM |
| 106 | |
| 107 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError &error); |
| 108 | #if QT_NETWORK_REMOVED_SINCE(6, 8) |
| 109 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError::SslError &error); |
| 110 | #endif |
| 111 | #endif |
| 112 | #else |
| 113 | class Q_NETWORK_EXPORT QSslError {}; // dummy class so that moc has a complete type |
| 114 | #endif // QT_NO_SSL |
| 115 | |
| 116 | QT_END_NAMESPACE |
| 117 | |
| 118 | #ifndef QT_NO_SSL |
| 119 | QT_DECL_METATYPE_EXTERN_TAGGED(QList<QSslError>, QList_QSslError, Q_NETWORK_EXPORT) |
| 120 | #endif |
| 121 | |
| 122 | #endif |
| 123 | |