X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorenetwork.cpp;h=101f52766ba377dd95a512d2bb29b60c2534333b;hp=b734312bc4266e77fc5f68b1b12bb8c882677f4f;hb=04315f46a16fc3627218377071e008b6b9744992;hpb=9fc57dc2c000e80fb8bd746a090e2e8210e1278e diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index b734312b..101f5276 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -310,7 +310,7 @@ void CoreNetwork::removeChannelKey(const QString &channel) #ifdef HAVE_QCA2 -Cipher *CoreNetwork::cipher(const QString &target) const +Cipher *CoreNetwork::cipher(const QString &target) { if (target.isEmpty()) return 0; @@ -318,39 +318,51 @@ Cipher *CoreNetwork::cipher(const QString &target) const if (!Cipher::neededFeaturesAvailable()) return 0; - QByteArray key = cipherKey(target); - if (key.isEmpty()) - return 0; - CoreIrcChannel *channel = qobject_cast(ircChannel(target)); if (channel) { - if (channel->cipher()->setKey(key)) - return channel->cipher(); + return channel->cipher(); } - else { - CoreIrcUser *user = qobject_cast(ircUser(target)); - if (user && user->cipher()->setKey(key)) - return user->cipher(); + CoreIrcUser *user = qobject_cast(ircUser(target)); + if (user) { + return user->cipher(); + } else if (!isChannelName(target)) { + return qobject_cast(newIrcUser(target))->cipher(); } return 0; } -QByteArray CoreNetwork::cipherKey(const QString &recipient) const +QByteArray CoreNetwork::cipherKey(const QString &target) const { - return _cipherKeys.value(recipient.toLower(), QByteArray()); + CoreIrcChannel *c = qobject_cast(ircChannel(target)); + if (c) + return c->cipher()->key(); + + CoreIrcUser *u = qobject_cast(ircUser(target)); + if (u) + return u->cipher()->key(); + + return QByteArray(); } -void CoreNetwork::setCipherKey(const QString &recipient, const QByteArray &key) +void CoreNetwork::setCipherKey(const QString &target, const QByteArray &key) { - if (!key.isEmpty()) - _cipherKeys[recipient.toLower()] = key; - else - _cipherKeys.remove(recipient.toLower()); -} + CoreIrcChannel *c = qobject_cast(ircChannel(target)); + if (c) { + c->setEncrypted(c->cipher()->setKey(key)); + return; + } + CoreIrcUser *u = qobject_cast(ircUser(target)); + if (!u && !isChannelName(target)) + u = qobject_cast(newIrcUser(target)); + if (u) { + u->setEncrypted(u->cipher()->setKey(key)); + return; + } +} #endif /* HAVE_QCA2 */ bool CoreNetwork::setAutoWhoDone(const QString &channel)