X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreircchannel.cpp;h=33c9efb1b241c1963e9b5970f7f4fe4164c1be87;hp=4f2f4f31dec448f40700545a8d64f1daf9ea63f1;hb=HEAD;hpb=84cd3561e97167ffb98ecab0fd2b884ba1d13ada diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index 4f2f4f31..7f9acd3b 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -19,29 +19,45 @@ ***************************************************************************/ #include "coreircchannel.h" + #include "corenetwork.h" -INIT_SYNCABLE_OBJECT(CoreIrcChannel) -CoreIrcChannel::CoreIrcChannel(const QString &channelname, Network *network) - : IrcChannel(channelname, network), - _receivedWelcomeMsg(false) +CoreIrcChannel::CoreIrcChannel(const QString& channelname, Network* network) + : IrcChannel(channelname, network) + , _receivedWelcomeMsg(false) { #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(channelname); + if (!key.isEmpty()) { + setEncrypted(cipher()->setKey(key)); + } + } #endif } - CoreIrcChannel::~CoreIrcChannel() { #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(name(), _cipher->key()); + } + delete _cipher; #endif } - #ifdef HAVE_QCA2 -Cipher *CoreIrcChannel::cipher() const +Cipher* CoreIrcChannel::cipher() const { if (!_cipher) _cipher = new Cipher(); @@ -49,7 +65,6 @@ Cipher *CoreIrcChannel::cipher() const return _cipher; } - void CoreIrcChannel::setEncrypted(bool e) { IrcChannel::setEncrypted(e); @@ -66,5 +81,4 @@ void CoreIrcChannel::setEncrypted(bool e) } } - #endif