| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslcipher.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | - | |||||||||||||
| 35 | /*! | - | ||||||||||||
| 36 | \class QSslCipher | - | ||||||||||||
| 37 | \brief The QSslCipher class represents an SSL cryptographic cipher. | - | ||||||||||||
| 38 | \since 4.3 | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | \reentrant | - | ||||||||||||
| 41 | \ingroup network | - | ||||||||||||
| 42 | \ingroup ssl | - | ||||||||||||
| 43 | \ingroup shared | - | ||||||||||||
| 44 | \inmodule QtNetwork | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | QSslCipher stores information about one cryptographic cipher. It | - | ||||||||||||
| 47 | is most commonly used with QSslSocket, either for configuring | - | ||||||||||||
| 48 | which ciphers the socket can use, or for displaying the socket's | - | ||||||||||||
| 49 | ciphers to the user. | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | \sa QSslSocket, QSslKey | - | ||||||||||||
| 52 | */ | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | #include "qsslcipher.h" | - | ||||||||||||
| 55 | #include "qsslcipher_p.h" | - | ||||||||||||
| 56 | #include "qsslsocket.h" | - | ||||||||||||
| 57 | #include "qsslconfiguration.h" | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
| 60 | #include <QtCore/qdebug.h> | - | ||||||||||||
| 61 | #endif | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | /*! | - | ||||||||||||
| 66 | Constructs an empty QSslCipher object. | - | ||||||||||||
| 67 | */ | - | ||||||||||||
| 68 | QSslCipher::QSslCipher() | - | ||||||||||||
| 69 | : d(new QSslCipherPrivate) | - | ||||||||||||
| 70 | { | - | ||||||||||||
| 71 | } executed 8431 times by 17 tests: end of blockExecuted by:
| 8431 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | /*! | - | ||||||||||||
| 74 | \since 5.3 | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | Constructs a QSslCipher object for the cipher determined by \a | - | ||||||||||||
| 77 | name. The constructor accepts only supported ciphers (i.e., the | - | ||||||||||||
| 78 | \a name must identify a cipher in the list of ciphers returned by | - | ||||||||||||
| 79 | QSslSocket::supportedCiphers()). | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | You can call isNull() after construction to check if \a name | - | ||||||||||||
| 82 | correctly identified a supported cipher. | - | ||||||||||||
| 83 | */ | - | ||||||||||||
| 84 | QSslCipher::QSslCipher(const QString &name) | - | ||||||||||||
| 85 | : d(new QSslCipherPrivate) | - | ||||||||||||
| 86 | { | - | ||||||||||||
| 87 | foreach (const QSslCipher &cipher, QSslConfiguration::supportedCiphers()) { | - | ||||||||||||
| 88 | if (cipher.name() == name) {
| 11-2689 | ||||||||||||
| 89 | *this = cipher; | - | ||||||||||||
| 90 | return; executed 11 times by 1 test: return;Executed by:
| 11 | ||||||||||||
| 91 | } | - | ||||||||||||
| 92 | } executed 2689 times by 1 test: end of blockExecuted by:
| 2689 | ||||||||||||
| 93 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||
| 94 | - | |||||||||||||
| 95 | /*! | - | ||||||||||||
| 96 | Constructs a QSslCipher object for the cipher determined by \a | - | ||||||||||||
| 97 | name and \a protocol. The constructor accepts only supported | - | ||||||||||||
| 98 | ciphers (i.e., the \a name and \a protocol must identify a cipher | - | ||||||||||||
| 99 | in the list of ciphers returned by | - | ||||||||||||
| 100 | QSslSocket::supportedCiphers()). | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | You can call isNull() after construction to check if \a name and | - | ||||||||||||
| 103 | \a protocol correctly identified a supported cipher. | - | ||||||||||||
| 104 | */ | - | ||||||||||||
| 105 | QSslCipher::QSslCipher(const QString &name, QSsl::SslProtocol protocol) | - | ||||||||||||
| 106 | : d(new QSslCipherPrivate) | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | foreach (const QSslCipher &cipher, QSslConfiguration::supportedCiphers()) { | - | ||||||||||||
| 109 | if (cipher.name() == name && cipher.protocol() == protocol) {
| 0 | ||||||||||||
| 110 | *this = cipher; | - | ||||||||||||
| 111 | return; never executed: return; | 0 | ||||||||||||
| 112 | } | - | ||||||||||||
| 113 | } never executed: end of block | 0 | ||||||||||||
| 114 | } never executed: end of block | 0 | ||||||||||||
| 115 | - | |||||||||||||
| 116 | /*! | - | ||||||||||||
| 117 | Constructs an identical copy of the \a other cipher. | - | ||||||||||||
| 118 | */ | - | ||||||||||||
| 119 | QSslCipher::QSslCipher(const QSslCipher &other) | - | ||||||||||||
| 120 | : d(new QSslCipherPrivate) | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | *d.data() = *other.d.data(); | - | ||||||||||||
| 123 | } executed 3361 times by 16 tests: end of blockExecuted by:
| 3361 | ||||||||||||
| 124 | - | |||||||||||||
| 125 | /*! | - | ||||||||||||
| 126 | Destroys the QSslCipher object. | - | ||||||||||||
| 127 | */ | - | ||||||||||||
| 128 | QSslCipher::~QSslCipher() | - | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | /*! | - | ||||||||||||
| 133 | Copies the contents of \a other into this cipher, making the two | - | ||||||||||||
| 134 | ciphers identical. | - | ||||||||||||
| 135 | */ | - | ||||||||||||
| 136 | QSslCipher &QSslCipher::operator=(const QSslCipher &other) | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | *d.data() = *other.d.data(); | - | ||||||||||||
| 139 | return *this; executed 724 times by 8 tests: return *this;Executed by:
| 724 | ||||||||||||
| 140 | } | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | /*! | - | ||||||||||||
| 143 | \fn void QSslCipher::swap(QSslCipher &other) | - | ||||||||||||
| 144 | \since 5.0 | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | Swaps this cipher instance with \a other. This function is very | - | ||||||||||||
| 147 | fast and never fails. | - | ||||||||||||
| 148 | */ | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | /*! | - | ||||||||||||
| 151 | Returns \c true if this cipher is the same as \a other; otherwise, | - | ||||||||||||
| 152 | false is returned. | - | ||||||||||||
| 153 | */ | - | ||||||||||||
| 154 | bool QSslCipher::operator==(const QSslCipher &other) const | - | ||||||||||||
| 155 | { | - | ||||||||||||
| 156 | return d->name == other.d->name && d->protocol == other.d->protocol; executed 2102 times by 3 tests: return d->name == other.d->name && d->protocol == other.d->protocol;Executed by:
| 0-2102 | ||||||||||||
| 157 | } | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | /*! | - | ||||||||||||
| 160 | \fn bool QSslCipher::operator!=(const QSslCipher &other) const | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | Returns \c true if this cipher is not the same as \a other; | - | ||||||||||||
| 163 | otherwise, false is returned. | - | ||||||||||||
| 164 | */ | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | /*! | - | ||||||||||||
| 167 | Returns \c true if this is a null cipher; otherwise returns \c false. | - | ||||||||||||
| 168 | */ | - | ||||||||||||
| 169 | bool QSslCipher::isNull() const | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | return d->isNull; executed 1211 times by 15 tests: return d->isNull;Executed by:
| 1211 | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | /*! | - | ||||||||||||
| 175 | Returns the name of the cipher, or an empty QString if this is a null | - | ||||||||||||
| 176 | cipher. | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | \sa isNull() | - | ||||||||||||
| 179 | */ | - | ||||||||||||
| 180 | QString QSslCipher::name() const | - | ||||||||||||
| 181 | { | - | ||||||||||||
| 182 | return d->name; executed 36004 times by 16 tests: return d->name;Executed by:
| 36004 | ||||||||||||
| 183 | } | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | /*! | - | ||||||||||||
| 186 | Returns the number of bits supported by the cipher. | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | \sa usedBits() | - | ||||||||||||
| 189 | */ | - | ||||||||||||
| 190 | int QSslCipher::supportedBits()const | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | return d->supportedBits; never executed: return d->supportedBits; | 0 | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | /*! | - | ||||||||||||
| 196 | Returns the number of bits used by the cipher. | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | \sa supportedBits() | - | ||||||||||||
| 199 | */ | - | ||||||||||||
| 200 | int QSslCipher::usedBits() const | - | ||||||||||||
| 201 | { | - | ||||||||||||
| 202 | return d->bits; executed 1875 times by 15 tests: return d->bits;Executed by:
| 1875 | ||||||||||||
| 203 | } | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | /*! | - | ||||||||||||
| 206 | Returns the cipher's key exchange method as a QString. | - | ||||||||||||
| 207 | */ | - | ||||||||||||
| 208 | QString QSslCipher::keyExchangeMethod() const | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | return d->keyExchangeMethod; never executed: return d->keyExchangeMethod; | 0 | ||||||||||||
| 211 | } | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | /*! | - | ||||||||||||
| 214 | Returns the cipher's authentication method as a QString. | - | ||||||||||||
| 215 | */ | - | ||||||||||||
| 216 | QString QSslCipher::authenticationMethod() const | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | return d->authenticationMethod; never executed: return d->authenticationMethod; | 0 | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | /*! | - | ||||||||||||
| 222 | Returns the cipher's encryption method as a QString. | - | ||||||||||||
| 223 | */ | - | ||||||||||||
| 224 | QString QSslCipher::encryptionMethod() const | - | ||||||||||||
| 225 | { | - | ||||||||||||
| 226 | return d->encryptionMethod; never executed: return d->encryptionMethod; | 0 | ||||||||||||
| 227 | } | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | /*! | - | ||||||||||||
| 230 | Returns the cipher's protocol as a QString. | - | ||||||||||||
| 231 | - | |||||||||||||
| 232 | \sa protocol() | - | ||||||||||||
| 233 | */ | - | ||||||||||||
| 234 | QString QSslCipher::protocolString() const | - | ||||||||||||
| 235 | { | - | ||||||||||||
| 236 | return d->protocolString; executed 720 times by 1 test: return d->protocolString;Executed by:
| 720 | ||||||||||||
| 237 | } | - | ||||||||||||
| 238 | - | |||||||||||||
| 239 | /*! | - | ||||||||||||
| 240 | Returns the cipher's protocol type, or \l QSsl::UnknownProtocol if | - | ||||||||||||
| 241 | QSslCipher is unable to determine the protocol (protocolString() may | - | ||||||||||||
| 242 | contain more information). | - | ||||||||||||
| 243 | - | |||||||||||||
| 244 | \sa protocolString() | - | ||||||||||||
| 245 | */ | - | ||||||||||||
| 246 | QSsl::SslProtocol QSslCipher::protocol() const | - | ||||||||||||
| 247 | { | - | ||||||||||||
| 248 | return d->protocol; never executed: return d->protocol; | 0 | ||||||||||||
| 249 | } | - | ||||||||||||
| 250 | - | |||||||||||||
| 251 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
| 252 | QDebug operator<<(QDebug debug, const QSslCipher &cipher) | - | ||||||||||||
| 253 | { | - | ||||||||||||
| 254 | QDebugStateSaver saver(debug); | - | ||||||||||||
| 255 | debug.resetFormat().nospace().noquote(); | - | ||||||||||||
| 256 | debug << "QSslCipher(name=" << cipher.name() | - | ||||||||||||
| 257 | << ", bits=" << cipher.usedBits() | - | ||||||||||||
| 258 | << ", proto=" << cipher.protocolString() | - | ||||||||||||
| 259 | << ')'; | - | ||||||||||||
| 260 | return debug; executed 720 times by 1 test: return debug;Executed by:
| 720 | ||||||||||||
| 261 | } | - | ||||||||||||
| 262 | #endif | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |