X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=d16e42df2b3cc6dd9bec6e282cfc46dfe5b5a0ce;hb=2fde026f4e0509e164be0ccd50174cb6b1103d55;hp=3fd0ad5e75f405e08afd6a833636b264a1994297;hpb=3da47d9186d1d40dc8fe998a130813b84345760d;p=quassel.git diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 3fd0ad5e..d16e42df 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -41,6 +41,10 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network) _codecForDecoding(0) { setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); + + #ifdef HAVE_QCA2 + _cipher = 0; + #endif } IrcChannel::~IrcChannel() { @@ -541,3 +545,36 @@ QString IrcChannel::channelModeString() const { else return QString("+%1 %2").arg(modeString).arg(params.join(" ")); } + +#ifdef HAVE_QCA2 +Cipher* IrcChannel::cipher() { + if(!_cipher) + _cipher = new Cipher(); + return _cipher; +} +#endif + +void IrcChannel::setEncrypted(bool e) { + if(e) { + #ifdef HAVE_QCA2 + if(topic().isEmpty()) + return; + + QByteArray key = network->bufferKey(name()); + if (key.isEmpty()) + return; + + if(!cipher()->setKey(key)) + return; + + //only send encrypted text to decrypter + int index = topic().indexOf(":",topic().indexOf(":")+1); + + QString backup = topic().mid(0,index+1); + QString decrypted = cipher()->decryptTopic(topic().mid(index+1).toAscii());; + decrypted.prepend(backup); + + setTopic(decodeString(decrypted.toAscii())); + #endif + } +} \ No newline at end of file