summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/ssl
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-09-25 15:55:35 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-10-19 07:32:37 +0200
commite8bdc949fc3646ff323a4fb4b83835e089a86b77 (patch)
tree2fe58431501cec9f66d514be66ba39bff4b9121f /tests/auto/network/ssl
parentadadb5e870c1b805aa3dabe12ae29005c8f1a406 (diff)
Add qHash(QSslCertificate) overload
qsslsocket_winrt.cpp defined it locally, which runs the risk of clashes with a potential user-defined qHash(QSslCertificate), so make it public. Also, the implementation in qsslsocket_winrt.cpp simply hashed the handle(), which violates the principle that equal instances must hash to the same value. Also, for some platforms, the implementation returns nullptr unconditionally, which, while not violating the above-mentioned principle, will make all users of the hash have worst-case complexity. To calculate a meaningful hash, therefore, the certificate needs to be inspected deeper than just the handle. For OpenSSL, we use X509::sha1_hash, which also X509_cmp uses internally to determine inequality (it checks more stuff, but if X059::sha1_hash is different, X509_cmp() returns non-zero, which is sufficient for the purposes of qHash()). sha1_hash may not be up-to-date, though, so we call X509_cmp to make it valid. Ugh. For WinRT/Qt, we use the DER encoding, as that is the native storage format used in QSslCertificate. This is not equivalent to the implementation used in qsslsocket_winrt.cpp before, but since handle() == handle() => toDer() == toDer(), it should not be a problem. [ChangeLog][QtNetwork][QSslCertificate] Can now be used as a key in QSet/QHash. Change-Id: I10858fe648c70fc9535af6913dd3b7f3b2cf0eba Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'tests/auto/network/ssl')
-rw-r--r--tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
index 67cbd5059f..49ff1b48fe 100644
--- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
+++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
@@ -70,6 +70,7 @@ public slots:
#ifndef QT_NO_SSL
private slots:
+ void hash();
void emptyConstructor();
void constructor_data();
void constructor();
@@ -164,6 +165,14 @@ void tst_QSslCertificate::cleanupTestCase()
#ifndef QT_NO_SSL
+void tst_QSslCertificate::hash()
+{
+ // mostly a compile-only test, to check that qHash(QSslCertificate) is found.
+ QSet<QSslCertificate> certs;
+ certs << QSslCertificate();
+ QCOMPARE(certs.size(), 1);
+}
+
static QByteArray readFile(const QString &absFilePath)
{
QFile file(absFilePath);