Use a union for different openssl types

Since the algorithm can only be one the underlying structure can
share the same memory.

Change-Id: Ifeaa1a2d5c4ad3566cbbf847445b805876275260
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Richard J. Moore <rich@kde.org>
bb10
André Klitzing 2015-01-19 12:53:01 +01:00
parent 2af1277631
commit 2688725eb7
2 changed files with 10 additions and 15 deletions

View File

@ -52,24 +52,24 @@ void QSslKeyPrivate::clear(bool deep)
isNull = true;
if (!QSslSocket::supportsSsl())
return;
if (rsa) {
if (algorithm == QSsl::Rsa && rsa) {
if (deep)
q_RSA_free(rsa);
rsa = 0;
}
if (dsa) {
if (algorithm == QSsl::Dsa && dsa) {
if (deep)
q_DSA_free(dsa);
dsa = 0;
}
#ifndef OPENSSL_NO_EC
if (ec) {
if (algorithm == QSsl::Ec && ec) {
if (deep)
q_EC_KEY_free(ec);
ec = 0;
}
#endif
if (opaque) {
if (algorithm == QSsl::Opaque && opaque) {
if (deep)
q_EVP_PKEY_free(opaque);
opaque = 0;

View File

@ -62,13 +62,6 @@ class QSslKeyPrivate
public:
inline QSslKeyPrivate()
: opaque(0)
#ifndef QT_NO_OPENSSL
, rsa(0)
, dsa(0)
#ifndef OPENSSL_NO_EC
, ec(0)
#endif
#endif
{
clear();
}
@ -97,12 +90,14 @@ public:
QSsl::KeyType type;
QSsl::KeyAlgorithm algorithm;
#ifndef QT_NO_OPENSSL
EVP_PKEY *opaque;
RSA *rsa;
DSA *dsa;
union {
EVP_PKEY *opaque;
RSA *rsa;
DSA *dsa;
#ifndef OPENSSL_NO_EC
EC_KEY *ec;
EC_KEY *ec;
#endif
};
#else
enum Cipher {
DesCbc,