Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsslellipticcurve.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 Governikus GmbH & Co. KG.
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
7#include "qsslsocket_p.h"
8
9#ifndef QT_NO_DEBUG_STREAM
10#include <QDebug>
11#endif
12
14
15QT_IMPL_METATYPE_EXTERN(QSslEllipticCurve)
16
17/*!
18 \class QSslEllipticCurve
19 \since 5.5
20
21 \brief Represents an elliptic curve for use by elliptic-curve cipher algorithms.
22
23 \reentrant
24 \ingroup network
25 \ingroup ssl
26 \inmodule QtNetwork
27
28 The class QSslEllipticCurve represents an elliptic curve for use by
29 elliptic-curve cipher algorithms.
30
31 Elliptic curves can be constructed from a "short name" (SN) (fromShortName()),
32 and by a call to QSslConfiguration::supportedEllipticCurves().
33
34 QSslEllipticCurve instances can be compared for equality and can be used as keys
35 in QHash and QSet. They cannot be used as key in a QMap.
36
37 \note This class is currently only supported in OpenSSL.
38*/
39
40/*!
41 \fn QSslEllipticCurve::QSslEllipticCurve()
42
43 Constructs an invalid elliptic curve.
44
45 \sa isValid(), QSslConfiguration::supportedEllipticCurves()
46*/
47
48/*!
49 Returns an QSslEllipticCurve instance representing the
50 named curve \a name. The \a name is the conventional short
51 name for the curve, as represented by RFC 4492 (for instance \c{secp521r1}),
52 or as NIST short names (for instance \c{P-256}). The actual set of
53 recognized names depends on the SSL implementation.
54
55 If the given \a name is not supported, returns an invalid QSslEllipticCurve instance.
56
57 \note The OpenSSL implementation of this function treats the name case-sensitively.
58
59 \sa shortName()
60*/
61QSslEllipticCurve QSslEllipticCurve::fromShortName(const QString &name)
62{
63 QSslEllipticCurve result;
64 if (name.isEmpty())
65 return result;
66
67 if (const auto *tlsBackend = QSslSocketPrivate::tlsBackendInUse())
68 result.id = tlsBackend->curveIdFromShortName(name);
69
70 return result;
71}
72
73/*!
74 Returns an QSslEllipticCurve instance representing the named curve \a name.
75 The \a name is a long name for the curve, whose exact spelling depends on the
76 SSL implementation.
77
78 If the given \a name is not supported, returns an invalid QSslEllipticCurve instance.
79
80 \note The OpenSSL implementation of this function treats the name case-sensitively.
81
82 \sa longName()
83*/
84QSslEllipticCurve QSslEllipticCurve::fromLongName(const QString &name)
85{
86 QSslEllipticCurve result;
87 if (name.isEmpty())
88 return result;
89
90 if (const auto *tlsBackend = QSslSocketPrivate::tlsBackendInUse())
91 result.id = tlsBackend->curveIdFromLongName(name);
92
93 return result;
94}
95
96/*!
97 Returns the conventional short name for this curve. If this
98 curve is invalid, returns an empty string.
99
100 \sa longName()
101*/
102QString QSslEllipticCurve::shortName() const
103{
104 QString name;
105
106 if (const auto *tlsBackend = QSslSocketPrivate::tlsBackendInUse())
107 name = tlsBackend->shortNameForId(id);
108
109 return name;
110}
111
112/*!
113 Returns the conventional long name for this curve. If this
114 curve is invalid, returns an empty string.
115
116 \sa shortName()
117*/
118QString QSslEllipticCurve::longName() const
119{
120 QString name;
121
122 if (const auto *tlsBackend = QSslSocketPrivate::tlsBackendInUse())
123 name = tlsBackend->longNameForId(id);
124
125 return name;
126}
127
128/*!
129 \fn bool QSslEllipticCurve::isValid() const
130
131 Returns true if this elliptic curve is a valid curve, false otherwise.
132*/
133
134/*!
135 Returns true if this elliptic curve is one of the named curves that can be
136 used in the key exchange when using an elliptic curve cipher with TLS;
137 false otherwise.
138*/
139bool QSslEllipticCurve::isTlsNamedCurve() const noexcept
140{
141 if (const auto *tlsBackend = QSslSocketPrivate::tlsBackendInUse())
142 return tlsBackend->isTlsNamedCurve(id);
143
144 return false;
145}
146
147
148/*!
149 \fn bool QSslEllipticCurve::operator==(QSslEllipticCurve lhs, QSslEllipticCurve rhs)
150 \since 5.5
151
152 Returns true if the curve \a lhs represents the same curve of \a rhs;
153*/
154
155/*!
156 \fn bool QSslEllipticCurve::operator!=(QSslEllipticCurve lhs, QSslEllipticCurve rhs)
157 \since 5.5
158
159 Returns true if the curve \a lhs represents a different curve than \a rhs;
160 false otherwise.
161*/
162
163/*!
164 \fn size_t qHash(QSslEllipticCurve key, size_t seed)
165 \since 5.5
166 \qhashold{QHash}
167*/
168
169#ifndef QT_NO_DEBUG_STREAM
170/*!
171 \relates QSslEllipticCurve
172 \since 5.5
173
174 Writes the elliptic curve \a curve into the debug object \a debug for
175 debugging purposes.
176
177 \sa {Debugging Techniques}
178*/
179QDebug operator<<(QDebug debug, QSslEllipticCurve curve)
180{
181 QDebugStateSaver saver(debug);
182 debug.resetFormat().nospace();
183 debug << "QSslEllipticCurve(" << curve.shortName() << ')';
184 return debug;
185}
186#endif
187
188QT_END_NAMESPACE
Represents an elliptic curve for use by elliptic-curve cipher algorithms.
Q_NETWORK_EXPORT bool isTlsNamedCurve() const noexcept
Returns true if this elliptic curve is one of the named curves that can be used in the key exchange w...