}
#ifdef HAVE_QCA2
+Cipher *CoreNetwork::cipher(const QString &target) const {
+ if(target.isEmpty())
+ return 0;
+
+ QByteArray key = cipherKey(target);
+ if(key.isEmpty())
+ return 0;
+
+ CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(ircChannel(target));
+ if(channel) {
+ if(channel->cipher()->setKey(key))
+ return channel->cipher();
+ } else {
+ CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
+ if(user && user->cipher()->setKey(key))
+ return user->cipher();
+ }
+ return 0;
+}
+
QByteArray CoreNetwork::cipherKey(const QString &recipient) const {
return _cipherKeys.value(recipient.toLower(), QByteArray());
}
// Blowfish stuff
#ifdef HAVE_QCA2
+ Cipher *cipher(const QString &recipient) const;
QByteArray cipherKey(const QString &recipient) const;
void setCipherKey(const QString &recipient, const QByteArray &key);
#endif
#ifdef HAVE_QCA2
QByteArray CoreUserInputHandler::encrypt(const QString &target, const QByteArray &message_) const {
- if(target.isEmpty() || message_.isEmpty())
+ if(message_.isEmpty())
return message_;
- QByteArray key = network()->cipherKey(target);
- if(key.isEmpty())
+ Cipher *cipher = network()->cipher(target);
+ if(!cipher)
return message_;
QByteArray message = message_;
-
- CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(network()->ircChannel(target));
- if(channel) {
- if(channel->cipher()->setKey(key))
- channel->cipher()->encrypt(message);
- } else {
- CoreIrcUser *user = qobject_cast<CoreIrcUser *>(network()->ircUser(target));
- if(user && user->cipher()->setKey(key))
- user->cipher()->encrypt(message);
- }
-
+ cipher->encrypt(message);
return message;
}
#endif
#ifdef HAVE_QCA2
QByteArray IrcServerHandler::decrypt(const QString &bufferName, const QByteArray &message_, bool isTopic) {
- if(bufferName.isEmpty() || message_.isEmpty())
+ if(message_.isEmpty())
return message_;
- const QByteArray key = network()->cipherKey(bufferName);
- if(key.isEmpty())
+ Cipher *cipher = network()->cipher(bufferName);
+ if(!cipher)
return message_;
QByteArray message = message_;
-
- CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(network()->ircChannel(bufferName));
- if(channel) {
- if(channel->cipher()->setKey(key))
- message = isTopic? channel->cipher()->decryptTopic(message) : channel->cipher()->decrypt(message);
- } else {
- CoreIrcUser *user = qobject_cast<CoreIrcUser *>(network()->ircUser(bufferName));
- if(user && user->cipher()->setKey(key))
- message = user->cipher()->decrypt(message);
- }
-
+ message = isTopic? cipher->decryptTopic(message) : cipher->decrypt(message);
return message;
}
#endif