1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtNetwork module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 |
|
---|
43 | /*!
|
---|
44 | \class QSslCipher
|
---|
45 | \brief The QSslCipher class represents an SSL cryptographic cipher.
|
---|
46 | \since 4.3
|
---|
47 |
|
---|
48 | \reentrant
|
---|
49 | \ingroup io
|
---|
50 | \ingroup ssl
|
---|
51 | \inmodule QtNetwork
|
---|
52 |
|
---|
53 | QSslCipher stores information about one cryptographic cipher. It
|
---|
54 | is most commonly used with QSslSocket, either for configuring
|
---|
55 | which ciphers the socket can use, or for displaying the socket's
|
---|
56 | ciphers to the user.
|
---|
57 |
|
---|
58 | \sa QSslSocket, QSslKey
|
---|
59 | */
|
---|
60 |
|
---|
61 | #include "qsslcipher.h"
|
---|
62 | #include "qsslcipher_p.h"
|
---|
63 | #include "qsslsocket.h"
|
---|
64 |
|
---|
65 | #ifndef QT_NO_DEBUG_STREAM
|
---|
66 | #include <QtCore/qdebug.h>
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | /*!
|
---|
72 | Constructs an empty QSslCipher object.
|
---|
73 | */
|
---|
74 | QSslCipher::QSslCipher()
|
---|
75 | : d(new QSslCipherPrivate)
|
---|
76 | {
|
---|
77 | }
|
---|
78 |
|
---|
79 | /*!
|
---|
80 | Constructs a QSslCipher object for the cipher determined by \a
|
---|
81 | name and \a protocol. The constructor accepts only supported
|
---|
82 | ciphers (i.e., the \a name and \a protocol must identify a cipher
|
---|
83 | in the list of ciphers returned by
|
---|
84 | QSslSocket::supportedCiphers()).
|
---|
85 |
|
---|
86 | You can call isNull() after construction to check if \a name and
|
---|
87 | \a protocol correctly identified a supported cipher.
|
---|
88 | */
|
---|
89 | QSslCipher::QSslCipher(const QString &name, QSsl::SslProtocol protocol)
|
---|
90 | : d(new QSslCipherPrivate)
|
---|
91 | {
|
---|
92 | foreach (const QSslCipher &cipher, QSslSocket::supportedCiphers()) {
|
---|
93 | if (cipher.name() == name && cipher.protocol() == protocol) {
|
---|
94 | *this = cipher;
|
---|
95 | return;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*!
|
---|
101 | Constructs an identical copy of the \a other cipher.
|
---|
102 | */
|
---|
103 | QSslCipher::QSslCipher(const QSslCipher &other)
|
---|
104 | : d(new QSslCipherPrivate)
|
---|
105 | {
|
---|
106 | *d = *other.d;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*!
|
---|
110 | Destroys the QSslCipher object.
|
---|
111 | */
|
---|
112 | QSslCipher::~QSslCipher()
|
---|
113 | {
|
---|
114 | delete d;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /*!
|
---|
118 | Copies the contents of \a other into this cipher, making the two
|
---|
119 | ciphers identical.
|
---|
120 | */
|
---|
121 | QSslCipher &QSslCipher::operator=(const QSslCipher &other)
|
---|
122 | {
|
---|
123 | *d = *other.d;
|
---|
124 | return *this;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /*!
|
---|
128 | Returns true if this cipher is the same as \a other; otherwise,
|
---|
129 | false is returned.
|
---|
130 | */
|
---|
131 | bool QSslCipher::operator==(const QSslCipher &other) const
|
---|
132 | {
|
---|
133 | return d->name == other.d->name && d->protocol == other.d->protocol;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*!
|
---|
137 | \fn bool QSslCipher::operator!=(const QSslCipher &other) const
|
---|
138 |
|
---|
139 | Returns true if this cipher is not the same as \a other;
|
---|
140 | otherwise, false is returned.
|
---|
141 | */
|
---|
142 |
|
---|
143 | /*!
|
---|
144 | Returns true if this is a null cipher; otherwise returns false.
|
---|
145 | */
|
---|
146 | bool QSslCipher::isNull() const
|
---|
147 | {
|
---|
148 | return d->isNull;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /*!
|
---|
152 | Returns the name of the cipher, or an empty QString if this is a null
|
---|
153 | cipher.
|
---|
154 |
|
---|
155 | \sa isNull()
|
---|
156 | */
|
---|
157 | QString QSslCipher::name() const
|
---|
158 | {
|
---|
159 | return d->name;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*!
|
---|
163 | Returns the number of bits supported by the cipher.
|
---|
164 |
|
---|
165 | \sa usedBits()
|
---|
166 | */
|
---|
167 | int QSslCipher::supportedBits()const
|
---|
168 | {
|
---|
169 | return d->supportedBits;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /*!
|
---|
173 | Returns the number of bits used by the cipher.
|
---|
174 |
|
---|
175 | \sa supportedBits()
|
---|
176 | */
|
---|
177 | int QSslCipher::usedBits() const
|
---|
178 | {
|
---|
179 | return d->bits;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /*!
|
---|
183 | Returns the cipher's key exchange method as a QString.
|
---|
184 | */
|
---|
185 | QString QSslCipher::keyExchangeMethod() const
|
---|
186 | {
|
---|
187 | return d->keyExchangeMethod;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /*!
|
---|
191 | Returns the cipher's authentication method as a QString.
|
---|
192 | */
|
---|
193 | QString QSslCipher::authenticationMethod() const
|
---|
194 | {
|
---|
195 | return d->authenticationMethod;
|
---|
196 | }
|
---|
197 |
|
---|
198 | /*!
|
---|
199 | Returns the cipher's encryption method as a QString.
|
---|
200 | */
|
---|
201 | QString QSslCipher::encryptionMethod() const
|
---|
202 | {
|
---|
203 | return d->encryptionMethod;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /*!
|
---|
207 | Returns the cipher's protocol as a QString.
|
---|
208 |
|
---|
209 | \sa protocol()
|
---|
210 | */
|
---|
211 | QString QSslCipher::protocolString() const
|
---|
212 | {
|
---|
213 | return d->protocolString;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /*!
|
---|
217 | Returns the cipher's protocol type, or \l QSsl::UnknownProtocol if
|
---|
218 | QSslCipher is unable to determine the protocol (protocolString() may
|
---|
219 | contain more information).
|
---|
220 |
|
---|
221 | \sa protocolString()
|
---|
222 | */
|
---|
223 | QSsl::SslProtocol QSslCipher::protocol() const
|
---|
224 | {
|
---|
225 | return d->protocol;
|
---|
226 | }
|
---|
227 |
|
---|
228 | #ifndef QT_NO_DEBUG_STREAM
|
---|
229 | QDebug operator<<(QDebug debug, const QSslCipher &cipher)
|
---|
230 | {
|
---|
231 | debug << "QSslCipher(name=" << qPrintable(cipher.name())
|
---|
232 | << ", bits=" << cipher.usedBits()
|
---|
233 | << ", proto=" << qPrintable(cipher.protocolString())
|
---|
234 | << ")";
|
---|
235 | return debug;
|
---|
236 | }
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | QT_END_NAMESPACE
|
---|