X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreircuser.cpp;h=0d5989944a4ae1a32d2f65ab43d3d013283fc155;hp=c89e9326b22c29a58406b1c3efe9c8f1bc1af3b6;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf diff --git a/src/core/coreircuser.cpp b/src/core/coreircuser.cpp index c89e9326..0d598994 100644 --- a/src/core/coreircuser.cpp +++ b/src/core/coreircuser.cpp @@ -20,24 +20,46 @@ #include "coreircuser.h" -CoreIrcUser::CoreIrcUser(const QString &hostmask, Network *network) : IrcUser(hostmask, network) +#include "corenetwork.h" + +CoreIrcUser::CoreIrcUser(const QString& hostmask, Network* network) + : IrcUser(hostmask, network) { #ifdef HAVE_QCA2 - _cipher = 0; + _cipher = nullptr; + + // Get the cipher key from CoreNetwork if present + auto* coreNetwork = qobject_cast(network); + if (coreNetwork) { + QByteArray key = coreNetwork->readChannelCipherKey(nick().toLower()); + if (!key.isEmpty()) { + if (!_cipher) { + _cipher = new Cipher(); + } + setEncrypted(_cipher->setKey(key)); + } + } #endif } - CoreIrcUser::~CoreIrcUser() { #ifdef HAVE_QCA2 + // Store the cipher key in CoreNetwork, including empty keys if a cipher + // exists. There is no need to store the empty key if no cipher exists; no + // key was present when instantiating and no key was set during the + // channel's lifetime. + auto* coreNetwork = qobject_cast(network()); + if (coreNetwork && _cipher) { + coreNetwork->storeChannelCipherKey(nick().toLower(), _cipher->key()); + } + delete _cipher; #endif } - #ifdef HAVE_QCA2 -Cipher *CoreIrcUser::cipher() const +Cipher* CoreIrcUser::cipher() const { if (!_cipher) _cipher = new Cipher(); @@ -45,5 +67,4 @@ Cipher *CoreIrcUser::cipher() const return _cipher; } - #endif