|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 network |
|
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 #endif |
|
68 |
|
69 QT_BEGIN_NAMESPACE |
|
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.data() = *other.d.data(); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Destroys the QSslCipher object. |
|
111 */ |
|
112 QSslCipher::~QSslCipher() |
|
113 { |
|
114 } |
|
115 |
|
116 /*! |
|
117 Copies the contents of \a other into this cipher, making the two |
|
118 ciphers identical. |
|
119 */ |
|
120 QSslCipher &QSslCipher::operator=(const QSslCipher &other) |
|
121 { |
|
122 *d.data() = *other.d.data(); |
|
123 return *this; |
|
124 } |
|
125 |
|
126 /*! |
|
127 Returns true if this cipher is the same as \a other; otherwise, |
|
128 false is returned. |
|
129 */ |
|
130 bool QSslCipher::operator==(const QSslCipher &other) const |
|
131 { |
|
132 return d->name == other.d->name && d->protocol == other.d->protocol; |
|
133 } |
|
134 |
|
135 /*! |
|
136 \fn bool QSslCipher::operator!=(const QSslCipher &other) const |
|
137 |
|
138 Returns true if this cipher is not the same as \a other; |
|
139 otherwise, false is returned. |
|
140 */ |
|
141 |
|
142 /*! |
|
143 Returns true if this is a null cipher; otherwise returns false. |
|
144 */ |
|
145 bool QSslCipher::isNull() const |
|
146 { |
|
147 return d->isNull; |
|
148 } |
|
149 |
|
150 /*! |
|
151 Returns the name of the cipher, or an empty QString if this is a null |
|
152 cipher. |
|
153 |
|
154 \sa isNull() |
|
155 */ |
|
156 QString QSslCipher::name() const |
|
157 { |
|
158 return d->name; |
|
159 } |
|
160 |
|
161 /*! |
|
162 Returns the number of bits supported by the cipher. |
|
163 |
|
164 \sa usedBits() |
|
165 */ |
|
166 int QSslCipher::supportedBits()const |
|
167 { |
|
168 return d->supportedBits; |
|
169 } |
|
170 |
|
171 /*! |
|
172 Returns the number of bits used by the cipher. |
|
173 |
|
174 \sa supportedBits() |
|
175 */ |
|
176 int QSslCipher::usedBits() const |
|
177 { |
|
178 return d->bits; |
|
179 } |
|
180 |
|
181 /*! |
|
182 Returns the cipher's key exchange method as a QString. |
|
183 */ |
|
184 QString QSslCipher::keyExchangeMethod() const |
|
185 { |
|
186 return d->keyExchangeMethod; |
|
187 } |
|
188 |
|
189 /*! |
|
190 Returns the cipher's authentication method as a QString. |
|
191 */ |
|
192 QString QSslCipher::authenticationMethod() const |
|
193 { |
|
194 return d->authenticationMethod; |
|
195 } |
|
196 |
|
197 /*! |
|
198 Returns the cipher's encryption method as a QString. |
|
199 */ |
|
200 QString QSslCipher::encryptionMethod() const |
|
201 { |
|
202 return d->encryptionMethod; |
|
203 } |
|
204 |
|
205 /*! |
|
206 Returns the cipher's protocol as a QString. |
|
207 |
|
208 \sa protocol() |
|
209 */ |
|
210 QString QSslCipher::protocolString() const |
|
211 { |
|
212 return d->protocolString; |
|
213 } |
|
214 |
|
215 /*! |
|
216 Returns the cipher's protocol type, or \l QSsl::UnknownProtocol if |
|
217 QSslCipher is unable to determine the protocol (protocolString() may |
|
218 contain more information). |
|
219 |
|
220 \sa protocolString() |
|
221 */ |
|
222 QSsl::SslProtocol QSslCipher::protocol() const |
|
223 { |
|
224 return d->protocol; |
|
225 } |
|
226 |
|
227 #ifndef QT_NO_DEBUG_STREAM |
|
228 QDebug operator<<(QDebug debug, const QSslCipher &cipher) |
|
229 { |
|
230 debug << "QSslCipher(name=" << qPrintable(cipher.name()) |
|
231 << ", bits=" << cipher.usedBits() |
|
232 << ", proto=" << qPrintable(cipher.protocolString()) |
|
233 << ')'; |
|
234 return debug; |
|
235 } |
|
236 #endif |
|
237 |
|
238 QT_END_NAMESPACE |