ssl/qsslkey.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtNetwork module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42 -
43/*! -
44 \class QSslKey -
45 \brief The QSslKey class provides an interface for private and public keys. -
46 \since 4.3 -
47 -
48 \reentrant -
49 \ingroup network -
50 \ingroup ssl -
51 \ingroup shared -
52 \inmodule QtNetwork -
53 -
54 QSslKey provides a simple API for managing keys. -
55 -
56 \sa QSslSocket, QSslCertificate, QSslCipher -
57*/ -
58 -
59#include "qsslkey.h" -
60#include "qsslkey_p.h" -
61#include "qsslsocket_openssl_symbols_p.h" -
62#include "qsslsocket.h" -
63#include "qsslsocket_p.h" -
64 -
65#include <QtCore/qatomic.h> -
66#include <QtCore/qbytearray.h> -
67#include <QtCore/qiodevice.h> -
68#ifndef QT_NO_DEBUG_STREAM -
69#include <QtCore/qdebug.h> -
70#endif -
71 -
72QT_BEGIN_NAMESPACE -
73 -
74/*! -
75 \internal -
76 */ -
77void QSslKeyPrivate::clear(bool deep) -
78{ -
79 isNull = true;
executed (the execution status of this line is deduced): isNull = true;
-
80 if (!QSslSocket::supportsSsl())
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10894
0-10894
81 return;
never executed: return;
0
82 if (rsa) {
evaluated: rsa
TRUEFALSE
yes
Evaluation Count:297
yes
Evaluation Count:10597
297-10597
83 if (deep)
partially evaluated: deep
TRUEFALSE
yes
Evaluation Count:297
no
Evaluation Count:0
0-297
84 q_RSA_free(rsa);
executed: q_RSA_free(rsa);
Execution Count:297
297
85 rsa = 0;
executed (the execution status of this line is deduced): rsa = 0;
-
86 }
executed: }
Execution Count:297
297
87 if (dsa) {
evaluated: dsa
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:10734
160-10734
88 if (deep)
partially evaluated: deep
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
0-160
89 q_DSA_free(dsa);
executed: q_DSA_free(dsa);
Execution Count:160
160
90 dsa = 0;
executed (the execution status of this line is deduced): dsa = 0;
-
91 }
executed: }
Execution Count:160
160
92 if (opaque) {
partially evaluated: opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10894
0-10894
93 if (deep)
never evaluated: deep
0
94 q_EVP_PKEY_free(opaque);
never executed: q_EVP_PKEY_free(opaque);
0
95 opaque = 0;
never executed (the execution status of this line is deduced): opaque = 0;
-
96 }
never executed: }
0
97}
executed: }
Execution Count:10894
10894
98 -
99/*! -
100 \internal -
101 -
102 Allocates a new rsa or dsa struct and decodes \a pem into it -
103 according to the current algorithm and type. -
104 -
105 If \a deepClear is true, the rsa/dsa struct is freed if it is was -
106 already allocated, otherwise we "leak" memory (which is exactly -
107 what we want for copy construction). -
108 -
109 If \a passPhrase is non-empty, it will be used for decrypting -
110 \a pem. -
111*/ -
112void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhrase, -
113 bool deepClear) -
114{ -
115 if (pem.isEmpty())
partially evaluated: pem.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
116 return;
never executed: return;
0
117 -
118 clear(deepClear);
executed (the execution status of this line is deduced): clear(deepClear);
-
119 -
120 if (!QSslSocket::supportsSsl())
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
121 return;
never executed: return;
0
122 -
123 BIO *bio = q_BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size());
executed (the execution status of this line is deduced): BIO *bio = q_BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size());
-
124 if (!bio)
partially evaluated: !bio
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
125 return;
never executed: return;
0
126 -
127 void *phrase = (void *)passPhrase.constData();
executed (the execution status of this line is deduced): void *phrase = (void *)passPhrase.constData();
-
128 -
129 if (algorithm == QSsl::Rsa) {
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:350
yes
Evaluation Count:192
192-350
130 RSA *result = (type == QSsl::PublicKey)
evaluated: (type == QSsl::PublicKey)
TRUEFALSE
yes
Evaluation Count:116
yes
Evaluation Count:234
116-234
131 ? q_PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, phrase)
executed (the execution status of this line is deduced): ? q_PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, phrase)
-
132 : q_PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, phrase);
executed (the execution status of this line is deduced): : q_PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, phrase);
-
133 if (rsa && rsa == result)
evaluated: rsa
TRUEFALSE
yes
Evaluation Count:291
yes
Evaluation Count:59
partially evaluated: rsa == result
TRUEFALSE
yes
Evaluation Count:291
no
Evaluation Count:0
0-291
134 isNull = false;
executed: isNull = false;
Execution Count:291
291
135 } else {
executed: }
Execution Count:350
350
136 DSA *result = (type == QSsl::PublicKey)
evaluated: (type == QSsl::PublicKey)
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:128
64-128
137 ? q_PEM_read_bio_DSA_PUBKEY(bio, &dsa, 0, phrase)
executed (the execution status of this line is deduced): ? q_PEM_read_bio_DSA_PUBKEY(bio, &dsa, 0, phrase)
-
138 : q_PEM_read_bio_DSAPrivateKey(bio, &dsa, 0, phrase);
executed (the execution status of this line is deduced): : q_PEM_read_bio_DSAPrivateKey(bio, &dsa, 0, phrase);
-
139 if (dsa && dsa == result)
evaluated: dsa
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:32
partially evaluated: dsa == result
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
0-160
140 isNull = false;
executed: isNull = false;
Execution Count:160
160
141 }
executed: }
Execution Count:192
192
142 -
143 q_BIO_free(bio);
executed (the execution status of this line is deduced): q_BIO_free(bio);
-
144}
executed: }
Execution Count:542
542
145 -
146/*! -
147 Constructs a null key. -
148 -
149 \sa isNull() -
150*/ -
151QSslKey::QSslKey() -
152 : d(new QSslKeyPrivate) -
153{ -
154}
executed: }
Execution Count:4634
4634
155 -
156/*! -
157 \internal -
158*/ -
159QByteArray QSslKeyPrivate::pemHeader() const -
160{ -
161 // ### use QByteArray::fromRawData() instead -
162 if (type == QSsl::PublicKey)
evaluated: type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:463
yes
Evaluation Count:627
463-627
163 return QByteArray("-----BEGIN PUBLIC KEY-----\n");
executed: return QByteArray("-----BEGIN PUBLIC KEY-----\n");
Execution Count:463
463
164 else if (algorithm == QSsl::Rsa)
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:399
yes
Evaluation Count:228
228-399
165 return QByteArray("-----BEGIN RSA PRIVATE KEY-----\n");
executed: return QByteArray("-----BEGIN RSA PRIVATE KEY-----\n");
Execution Count:399
399
166 return QByteArray("-----BEGIN DSA PRIVATE KEY-----\n");
executed: return QByteArray("-----BEGIN DSA PRIVATE KEY-----\n");
Execution Count:228
228
167} -
168 -
169/*! -
170 \internal -
171*/ -
172QByteArray QSslKeyPrivate::pemFooter() const -
173{ -
174 // ### use QByteArray::fromRawData() instead -
175 if (type == QSsl::PublicKey)
evaluated: type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:463
yes
Evaluation Count:627
463-627
176 return QByteArray("-----END PUBLIC KEY-----\n");
executed: return QByteArray("-----END PUBLIC KEY-----\n");
Execution Count:463
463
177 else if (algorithm == QSsl::Rsa)
evaluated: algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:399
yes
Evaluation Count:228
228-399
178 return QByteArray("-----END RSA PRIVATE KEY-----\n");
executed: return QByteArray("-----END RSA PRIVATE KEY-----\n");
Execution Count:399
399
179 return QByteArray("-----END DSA PRIVATE KEY-----\n");
executed: return QByteArray("-----END DSA PRIVATE KEY-----\n");
Execution Count:228
228
180} -
181 -
182/*! -
183 \internal -
184 -
185 Returns a DER key formatted as PEM. -
186*/ -
187QByteArray QSslKeyPrivate::pemFromDer(const QByteArray &der) const -
188{ -
189 QByteArray pem(der.toBase64());
executed (the execution status of this line is deduced): QByteArray pem(der.toBase64());
-
190 -
191 const int lineWidth = 64; // RFC 1421
executed (the execution status of this line is deduced): const int lineWidth = 64;
-
192 const int newLines = pem.size() / lineWidth;
executed (the execution status of this line is deduced): const int newLines = pem.size() / lineWidth;
-
193 const bool rem = pem.size() % lineWidth;
executed (the execution status of this line is deduced): const bool rem = pem.size() % lineWidth;
-
194 -
195 // ### optimize -
196 for (int i = 0; i < newLines; ++i)
evaluated: i < newLines
TRUEFALSE
yes
Evaluation Count:2054
yes
Evaluation Count:266
266-2054
197 pem.insert((i + 1) * lineWidth + i, '\n');
executed: pem.insert((i + 1) * lineWidth + i, '\n');
Execution Count:2054
2054
198 if (rem)
evaluated: rem
TRUEFALSE
yes
Evaluation Count:250
yes
Evaluation Count:16
16-250
199 pem.append('\n'); // ###
executed: pem.append('\n');
Execution Count:250
250
200 -
201 pem.prepend(pemHeader());
executed (the execution status of this line is deduced): pem.prepend(pemHeader());
-
202 pem.append(pemFooter());
executed (the execution status of this line is deduced): pem.append(pemFooter());
-
203 -
204 return pem;
executed: return pem;
Execution Count:266
266
205} -
206 -
207/*! -
208 \internal -
209 -
210 Returns a PEM key formatted as DER. -
211*/ -
212QByteArray QSslKeyPrivate::derFromPem(const QByteArray &pem) const -
213{ -
214 const QByteArray header = pemHeader();
executed (the execution status of this line is deduced): const QByteArray header = pemHeader();
-
215 const QByteArray footer = pemFooter();
executed (the execution status of this line is deduced): const QByteArray footer = pemFooter();
-
216 -
217 QByteArray der(pem);
executed (the execution status of this line is deduced): QByteArray der(pem);
-
218 -
219 const int headerIndex = der.indexOf(header);
executed (the execution status of this line is deduced): const int headerIndex = der.indexOf(header);
-
220 const int footerIndex = der.indexOf(footer);
executed (the execution status of this line is deduced): const int footerIndex = der.indexOf(footer);
-
221 if (headerIndex == -1 || footerIndex == -1)
partially evaluated: headerIndex == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
partially evaluated: footerIndex == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
0-824
222 return QByteArray();
never executed: return QByteArray();
0
223 -
224 der = der.mid(headerIndex + header.size(), footerIndex - (headerIndex + header.size()));
executed (the execution status of this line is deduced): der = der.mid(headerIndex + header.size(), footerIndex - (headerIndex + header.size()));
-
225 -
226 return QByteArray::fromBase64(der); // ignores newlines
executed: return QByteArray::fromBase64(der);
Execution Count:824
824
227} -
228 -
229/*! -
230 Constructs a QSslKey by decoding the string in the byte array -
231 \a encoded using a specified \a algorithm and \a encoding format. -
232 If the encoded key is encrypted, \a passPhrase is used to decrypt -
233 it. \a type specifies whether the key is public or private. -
234 -
235 After construction, use isNull() to check if \a encoded contained -
236 a valid key. -
237*/ -
238QSslKey::QSslKey(const QByteArray &encoded, QSsl::KeyAlgorithm algorithm, -
239 QSsl::EncodingFormat encoding, QSsl::KeyType type, const QByteArray &passPhrase) -
240 : d(new QSslKeyPrivate) -
241{ -
242 d->type = type;
executed (the execution status of this line is deduced): d->type = type;
-
243 d->algorithm = algorithm;
executed (the execution status of this line is deduced): d->algorithm = algorithm;
-
244 d->decodePem((encoding == QSsl::Der)
executed (the execution status of this line is deduced): d->decodePem((encoding == QSsl::Der)
-
245 ? d->pemFromDer(encoded) : encoded,
executed (the execution status of this line is deduced): ? d->pemFromDer(encoded) : encoded,
-
246 passPhrase);
executed (the execution status of this line is deduced): passPhrase);
-
247}
executed: }
Execution Count:535
535
248 -
249/*! -
250 Constructs a QSslKey by reading and decoding data from a -
251 \a device using a specified \a algorithm and \a encoding format. -
252 If the encoded key is encrypted, \a passPhrase is used to decrypt -
253 it. \a type specifies whether the key is public or private. -
254 -
255 After construction, use isNull() to check if \a device provided -
256 a valid key. -
257*/ -
258QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::EncodingFormat encoding, -
259 QSsl::KeyType type, const QByteArray &passPhrase) -
260 : d(new QSslKeyPrivate) -
261{ -
262 QByteArray encoded;
executed (the execution status of this line is deduced): QByteArray encoded;
-
263 if (device)
partially evaluated: device
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
264 encoded = device->readAll();
executed: encoded = device->readAll();
Execution Count:7
7
265 d->type = type;
executed (the execution status of this line is deduced): d->type = type;
-
266 d->algorithm = algorithm;
executed (the execution status of this line is deduced): d->algorithm = algorithm;
-
267 d->decodePem((encoding == QSsl::Der) ?
executed (the execution status of this line is deduced): d->decodePem((encoding == QSsl::Der) ?
-
268 d->pemFromDer(encoded) : encoded,
executed (the execution status of this line is deduced): d->pemFromDer(encoded) : encoded,
-
269 passPhrase);
executed (the execution status of this line is deduced): passPhrase);
-
270}
executed: }
Execution Count:7
7
271 -
272/*! -
273 \since 5.0 -
274 Constructs a QSslKey from a valid native key \a handle. -
275 \a type specifies whether the key is public or private. -
276 -
277 QSslKey will take ownership for this key and you must not -
278 free the key using the native library. The algorithm used -
279 when creating a key from a handle will always be QSsl::Opaque. -
280*/ -
281QSslKey::QSslKey(Qt::HANDLE handle, QSsl::KeyType type) -
282 : d(new QSslKeyPrivate) -
283{ -
284 d->opaque = reinterpret_cast<EVP_PKEY *>(handle);
never executed (the execution status of this line is deduced): d->opaque = reinterpret_cast<EVP_PKEY *>(handle);
-
285 d->algorithm = QSsl::Opaque;
never executed (the execution status of this line is deduced): d->algorithm = QSsl::Opaque;
-
286 d->type = type;
never executed (the execution status of this line is deduced): d->type = type;
-
287 d->isNull = !d->opaque;
never executed (the execution status of this line is deduced): d->isNull = !d->opaque;
-
288}
never executed: }
0
289 -
290/*! -
291 Constructs an identical copy of \a other. -
292*/ -
293QSslKey::QSslKey(const QSslKey &other) : d(other.d) -
294{ -
295}
executed: }
Execution Count:297
297
296 -
297/*! -
298 Destroys the QSslKey object. -
299*/ -
300QSslKey::~QSslKey() -
301{ -
302} -
303 -
304/*! -
305 Copies the contents of \a other into this key, making the two keys -
306 identical. -
307 -
308 Returns a reference to this QSslKey. -
309*/ -
310QSslKey &QSslKey::operator=(const QSslKey &other) -
311{ -
312 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
313 return *this;
executed: return *this;
Execution Count:147
147
314} -
315 -
316/*! -
317 \fn void QSslKey::swap(QSslKey &other) -
318 \since 5.0 -
319 -
320 Swaps this ssl key with \a other. This function is very fast and -
321 never fails. -
322*/ -
323 -
324/*! -
325 Returns true if this is a null key; otherwise false. -
326 -
327 \sa clear() -
328*/ -
329bool QSslKey::isNull() const -
330{ -
331 return d->isNull;
executed: return d->isNull;
Execution Count:979
979
332} -
333 -
334/*! -
335 Clears the contents of this key, making it a null key. -
336 -
337 \sa isNull() -
338*/ -
339void QSslKey::clear() -
340{ -
341 d = new QSslKeyPrivate;
never executed (the execution status of this line is deduced): d = new QSslKeyPrivate;
-
342}
never executed: }
0
343 -
344/*! -
345 Returns the length of the key in bits, or -1 if the key is null. -
346*/ -
347int QSslKey::length() const -
348{ -
349 if (d->isNull || d->algorithm == QSsl::Opaque)
evaluated: d->isNull
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:582
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:582
0-582
350 return -1;
executed: return -1;
Execution Count:1
1
351 -
352 return (d->algorithm == QSsl::Rsa)
executed: return (d->algorithm == QSsl::Rsa) ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p);
Execution Count:582
582
353 ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p);
executed: return (d->algorithm == QSsl::Rsa) ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p);
Execution Count:582
582
354} -
355 -
356/*! -
357 Returns the type of the key (i.e., PublicKey or PrivateKey). -
358*/ -
359QSsl::KeyType QSslKey::type() const -
360{ -
361 return d->type;
executed: return d->type;
Execution Count:538
538
362} -
363 -
364/*! -
365 Returns the key algorithm. -
366*/ -
367QSsl::KeyAlgorithm QSslKey::algorithm() const -
368{ -
369 return d->algorithm;
executed: return d->algorithm;
Execution Count:728
728
370} -
371 -
372/*! -
373 Returns the key in DER encoding. The result is encrypted with -
374 \a passPhrase if the key is a private key and \a passPhrase is -
375 non-empty. -
376*/ -
377// ### autotest failure for non-empty passPhrase and private key -
378QByteArray QSslKey::toDer(const QByteArray &passPhrase) const -
379{ -
380 if (d->isNull || d->algorithm == QSsl::Opaque)
partially evaluated: d->isNull
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:824
0-824
381 return QByteArray();
never executed: return QByteArray();
0
382 -
383 return d->derFromPem(toPem(passPhrase));
executed: return d->derFromPem(toPem(passPhrase));
Execution Count:824
824
384} -
385 -
386/*! -
387 Returns the key in PEM encoding. The result is encrypted with -
388 \a passPhrase if the key is a private key and \a passPhrase is -
389 non-empty. -
390*/ -
391QByteArray QSslKey::toPem(const QByteArray &passPhrase) const -
392{ -
393 if (!QSslSocket::supportsSsl() || d->isNull || d->algorithm == QSsl::Opaque)
partially evaluated: !QSslSocket::supportsSsl()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1638
evaluated: d->isNull
TRUEFALSE
yes
Evaluation Count:88
yes
Evaluation Count:1550
partially evaluated: d->algorithm == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1550
0-1638
394 return QByteArray();
executed: return QByteArray();
Execution Count:88
88
395 -
396 BIO *bio = q_BIO_new(q_BIO_s_mem());
executed (the execution status of this line is deduced): BIO *bio = q_BIO_new(q_BIO_s_mem());
-
397 if (!bio)
partially evaluated: !bio
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1550
0-1550
398 return QByteArray();
never executed: return QByteArray();
0
399 -
400 bool fail = false;
executed (the execution status of this line is deduced): bool fail = false;
-
401 -
402 if (d->algorithm == QSsl::Rsa) {
evaluated: d->algorithm == QSsl::Rsa
TRUEFALSE
yes
Evaluation Count:990
yes
Evaluation Count:560
560-990
403 if (d->type == QSsl::PublicKey) {
evaluated: d->type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:416
yes
Evaluation Count:574
416-574
404 if (!q_PEM_write_bio_RSA_PUBKEY(bio, d->rsa))
partially evaluated: !q_PEM_write_bio_RSA_PUBKEY(bio, d->rsa)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:416
0-416
405 fail = true;
never executed: fail = true;
0
406 } else {
executed: }
Execution Count:416
416
407 if (!q_PEM_write_bio_RSAPrivateKey(
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
408 bio, d->rsa,
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
409 // ### the cipher should be selectable in the API:
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
410 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
411 (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)) {
partially evaluated: !q_PEM_write_bio_RSAPrivateKey( bio, d->rsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:574
0-574
412 fail = true;
never executed (the execution status of this line is deduced): fail = true;
-
413 }
never executed: }
0
414 }
executed: }
Execution Count:574
574
415 } else { -
416 if (d->type == QSsl::PublicKey) {
evaluated: d->type == QSsl::PublicKey
TRUEFALSE
yes
Evaluation Count:232
yes
Evaluation Count:328
232-328
417 if (!q_PEM_write_bio_DSA_PUBKEY(bio, d->dsa))
partially evaluated: !q_PEM_write_bio_DSA_PUBKEY(bio, d->dsa)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:232
0-232
418 fail = true;
never executed: fail = true;
0
419 } else {
executed: }
Execution Count:232
232
420 if (!q_PEM_write_bio_DSAPrivateKey(
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
421 bio, d->dsa,
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
422 // ### the cipher should be selectable in the API:
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
423 passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(),
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
424 (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)) {
partially evaluated: !q_PEM_write_bio_DSAPrivateKey( bio, d->dsa, passPhrase.isEmpty() ? (const EVP_CIPHER *)0 : q_EVP_des_ede3_cbc(), (uchar *)passPhrase.data(), passPhrase.size(), 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:328
0-328
425 fail = true;
never executed (the execution status of this line is deduced): fail = true;
-
426 }
never executed: }
0
427 }
executed: }
Execution Count:328
328
428 } -
429 -
430 QByteArray pem;
executed (the execution status of this line is deduced): QByteArray pem;
-
431 if (!fail) {
partially evaluated: !fail
TRUEFALSE
yes
Evaluation Count:1550
no
Evaluation Count:0
0-1550
432 char *data;
executed (the execution status of this line is deduced): char *data;
-
433 long size = q_BIO_get_mem_data(bio, &data);
executed (the execution status of this line is deduced): long size = (int)q_BIO_ctrl(bio,3,0,(char *)&data);
-
434 pem = QByteArray(data, size);
executed (the execution status of this line is deduced): pem = QByteArray(data, size);
-
435 }
executed: }
Execution Count:1550
1550
436 q_BIO_free(bio);
executed (the execution status of this line is deduced): q_BIO_free(bio);
-
437 return pem;
executed: return pem;
Execution Count:1550
1550
438} -
439 -
440/*! -
441 Returns a pointer to the native key handle, if it is available; -
442 otherwise a null pointer is returned. -
443 -
444 You can use this handle together with the native API to access -
445 extended information about the key. -
446 -
447 \warning Use of this function has a high probability of being -
448 non-portable, and its return value may vary across platforms, and -
449 between minor Qt releases. -
450*/ -
451Qt::HANDLE QSslKey::handle() const -
452{ -
453 switch (d->algorithm) { -
454 case QSsl::Opaque: -
455 return Qt::HANDLE(d->opaque);
never executed: return Qt::HANDLE(d->opaque);
0
456 case QSsl::Rsa: -
457 return Qt::HANDLE(d->rsa);
executed: return Qt::HANDLE(d->rsa);
Execution Count:3
3
458 case QSsl::Dsa: -
459 return Qt::HANDLE(d->dsa);
never executed: return Qt::HANDLE(d->dsa);
0
460 default: -
461 return Qt::HANDLE(NULL);
never executed: return Qt::HANDLE(__null);
0
462 } -
463}
never executed: }
0
464 -
465/*! -
466 Returns true if this key is equal to \a other; otherwise returns false. -
467*/ -
468bool QSslKey::operator==(const QSslKey &other) const -
469{ -
470 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:44
yes
Evaluation Count:181
44-181
471 return other.isNull();
executed: return other.isNull();
Execution Count:44
44
472 if (other.isNull())
partially evaluated: other.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
473 return isNull();
never executed: return isNull();
0
474 if (algorithm() != other.algorithm())
partially evaluated: algorithm() != other.algorithm()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
475 return false;
never executed: return false;
0
476 if (type() != other.type())
partially evaluated: type() != other.type()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
477 return false;
never executed: return false;
0
478 if (length() != other.length())
partially evaluated: length() != other.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
479 return false;
never executed: return false;
0
480 if (algorithm() == QSsl::Opaque)
partially evaluated: algorithm() == QSsl::Opaque
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
481 return handle() == other.handle();
never executed: return handle() == other.handle();
0
482 return toDer() == other.toDer();
executed: return toDer() == other.toDer();
Execution Count:181
181
483} -
484 -
485/*! \fn bool QSslKey::operator!=(const QSslKey &other) const -
486 -
487 Returns true if this key is not equal to key \a other; otherwise -
488 returns false. -
489*/ -
490 -
491#ifndef QT_NO_DEBUG_STREAM -
492class QDebug; -
493QDebug operator<<(QDebug debug, const QSslKey &key) -
494{ -
495 debug << "QSslKey("
never executed (the execution status of this line is deduced): debug << "QSslKey("
-
496 << (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey")
never executed (the execution status of this line is deduced): << (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey")
-
497 << ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" :
never executed (the execution status of this line is deduced): << ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" :
-
498 (key.algorithm() == QSsl::Rsa ? "RSA" : "DSA"))
never executed (the execution status of this line is deduced): (key.algorithm() == QSsl::Rsa ? "RSA" : "DSA"))
-
499 << ", " << key.length()
never executed (the execution status of this line is deduced): << ", " << key.length()
-
500 << ')';
never executed (the execution status of this line is deduced): << ')';
-
501 return debug;
never executed: return debug;
0
502} -
503#endif -
504 -
505QT_END_NAMESPACE -
506 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial