1// Copyright (C) 2015 Mikkel Krautz <mikkel@krautz.dk>
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:significant reason:default
4
5
6#ifndef QSSLDIFFIEHELLMANPARAMETERS_H
7#define QSSLDIFFIEHELLMANPARAMETERS_H
8
9#include <QtNetwork/qssl.h>
10#include <QtCore/qnamespace.h>
11#include <QtCore/qbytearray.h>
12#include <QtCore/qshareddata.h>
13
14QT_BEGIN_NAMESPACE
15
16#ifndef QT_NO_SSL
17
18class QIODevice;
19class QSslContext;
20class QSslDiffieHellmanParametersPrivate;
21
22class QSslDiffieHellmanParameters;
23// qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4)
24Q_NETWORK_EXPORT size_t qHash(const QSslDiffieHellmanParameters &dhparam, size_t seed = 0) noexcept;
25
26#ifndef QT_NO_DEBUG_STREAM
27class QDebug;
28Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslDiffieHellmanParameters &dhparams);
29#endif
30
31class Q_NETWORK_EXPORT QSslDiffieHellmanParameters
32{
33public:
34 enum Error {
35 NoError,
36 InvalidInputDataError,
37 UnsafeParametersError
38 };
39
40 static QSslDiffieHellmanParameters defaultParameters();
41
42 QSslDiffieHellmanParameters();
43 QSslDiffieHellmanParameters(const QSslDiffieHellmanParameters &other);
44 QSslDiffieHellmanParameters(QSslDiffieHellmanParameters &&other) noexcept : d(other.d) { other.d = nullptr; }
45 ~QSslDiffieHellmanParameters();
46
47 QSslDiffieHellmanParameters &operator=(const QSslDiffieHellmanParameters &other);
48 QSslDiffieHellmanParameters &operator=(QSslDiffieHellmanParameters &&other) noexcept { swap(other); return *this; }
49
50 void swap(QSslDiffieHellmanParameters &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); }
51
52 static QSslDiffieHellmanParameters fromEncoded(const QByteArray &encoded, QSsl::EncodingFormat format = QSsl::Pem);
53 static QSslDiffieHellmanParameters fromEncoded(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem);
54
55 bool isEmpty() const noexcept;
56 bool isValid() const noexcept;
57 Error error() const noexcept;
58 QString errorString() const noexcept;
59
60private:
61 QSslDiffieHellmanParametersPrivate *d;
62 friend class QSslContext;
63
64 bool isEqual(const QSslDiffieHellmanParameters &other) const noexcept;
65 friend bool operator==(const QSslDiffieHellmanParameters &lhs, const QSslDiffieHellmanParameters &rhs) noexcept
66 { return lhs.isEqual(other: rhs); }
67 friend bool operator!=(const QSslDiffieHellmanParameters &lhs, const QSslDiffieHellmanParameters &rhs) noexcept
68 { return !lhs.isEqual(other: rhs); }
69
70#ifndef QT_NO_DEBUG_STREAM
71 friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslDiffieHellmanParameters &dhparam);
72#endif
73 friend Q_NETWORK_EXPORT size_t qHash(const QSslDiffieHellmanParameters &dhparam, size_t seed) noexcept;
74};
75
76Q_DECLARE_SHARED(QSslDiffieHellmanParameters)
77
78#endif // QT_NO_SSL
79
80QT_END_NAMESPACE
81
82#endif
83

source code of qtbase/src/network/ssl/qssldiffiehellmanparameters.h