summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r--Swiften/Avatars/AvatarManagerImpl.cpp8
-rw-r--r--Swiften/Avatars/AvatarManagerImpl.h3
-rw-r--r--Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp18
-rw-r--r--Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp16
-rw-r--r--Swiften/Avatars/VCardAvatarManager.cpp8
-rw-r--r--Swiften/Avatars/VCardAvatarManager.h6
-rw-r--r--Swiften/Avatars/VCardUpdateAvatarManager.cpp6
-rw-r--r--Swiften/Avatars/VCardUpdateAvatarManager.h6
8 files changed, 43 insertions, 28 deletions
diff --git a/Swiften/Avatars/AvatarManagerImpl.cpp b/Swiften/Avatars/AvatarManagerImpl.cpp
index 78d94dc..7c3baa7 100644
--- a/Swiften/Avatars/AvatarManagerImpl.cpp
+++ b/Swiften/Avatars/AvatarManagerImpl.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -16,11 +16,11 @@
namespace Swift {
-AvatarManagerImpl::AvatarManagerImpl(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : avatarStorage(avatarStorage) {
- vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry);
+AvatarManagerImpl::AvatarManagerImpl(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, CryptoProvider* crypto, MUCRegistry* mucRegistry) : avatarStorage(avatarStorage) {
+ vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, crypto, mucRegistry);
combinedAvatarProvider.addProvider(vcardUpdateAvatarManager);
- vcardAvatarManager = new VCardAvatarManager(vcardManager, avatarStorage, mucRegistry);
+ vcardAvatarManager = new VCardAvatarManager(vcardManager, avatarStorage, crypto, mucRegistry);
combinedAvatarProvider.addProvider(vcardAvatarManager);
offlineAvatarManager = new OfflineAvatarManager(avatarStorage);
diff --git a/Swiften/Avatars/AvatarManagerImpl.h b/Swiften/Avatars/AvatarManagerImpl.h
index c2b8956..4f59fe5 100644
--- a/Swiften/Avatars/AvatarManagerImpl.h
+++ b/Swiften/Avatars/AvatarManagerImpl.h
@@ -17,10 +17,11 @@ namespace Swift {
class VCardUpdateAvatarManager;
class VCardAvatarManager;
class OfflineAvatarManager;
+ class CryptoProvider;
class AvatarManagerImpl : public AvatarManager {
public:
- AvatarManagerImpl(VCardManager*, StanzaChannel*, AvatarStorage*, MUCRegistry* = NULL);
+ AvatarManagerImpl(VCardManager*, StanzaChannel*, AvatarStorage*, CryptoProvider* crypto, MUCRegistry* = NULL);
virtual ~AvatarManagerImpl();
virtual boost::filesystem::path getAvatarPath(const JID&) const;
diff --git a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
index 81dc12c..dd76fb6 100644
--- a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
+++ b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -19,8 +19,9 @@
#include <Swiften/MUC/MUCRegistry.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Client/DummyStanzaChannel.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -37,6 +38,8 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
public:
class TestVCardStorage : public VCardStorage {
public:
+ TestVCardStorage(CryptoProvider* crypto) : VCardStorage(crypto), crypto(crypto) {}
+
virtual VCard::ref getVCard(const JID& jid) const {
VCardMap::const_iterator i = vcards.find(jid);
if (i != vcards.end()) {
@@ -57,7 +60,7 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
}
VCard::ref vCard = getVCard(jid);
if (vCard && !vCard->getPhoto().empty()) {
- return Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ return Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
}
else {
return "";
@@ -69,19 +72,21 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
private:
typedef std::map<JID, VCard::ref> VCardMap;
VCardMap vcards;
+ CryptoProvider* crypto;
};
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
ownJID = JID("foo@fum.com/bum");
stanzaChannel = new DummyStanzaChannel();
stanzaChannel->setAvailable(true);
iqRouter = new IQRouter(stanzaChannel);
mucRegistry = new DummyMUCRegistry();
avatarStorage = new AvatarMemoryStorage();
- vcardStorage = new TestVCardStorage();
+ vcardStorage = new TestVCardStorage(crypto.get());
vcardManager = new VCardManager(ownJID, iqRouter, vcardStorage);
avatar1 = createByteArray("abcdefg");
- avatar1Hash = Hexify::hexify(SHA1::getHash(avatar1));
+ avatar1Hash = Hexify::hexify(crypto->getSHA1Hash(avatar1));
user1 = JID("user1@bar.com/bla");
user2 = JID("user2@foo.com/baz");
}
@@ -153,7 +158,7 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<VCardAvatarManager> createManager() {
- boost::shared_ptr<VCardAvatarManager> result(new VCardAvatarManager(vcardManager, avatarStorage, mucRegistry));
+ boost::shared_ptr<VCardAvatarManager> result(new VCardAvatarManager(vcardManager, avatarStorage, crypto.get(), mucRegistry));
result->onAvatarChanged.connect(boost::bind(&VCardAvatarManagerTest::handleAvatarChanged, this, _1));
return result;
}
@@ -197,6 +202,7 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
std::vector<JID> changes;
JID user1;
JID user2;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(VCardAvatarManagerTest);
diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
index 60e76f8..01b10a2 100644
--- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
+++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -19,8 +19,9 @@
#include <Swiften/MUC/MUCRegistry.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Client/DummyStanzaChannel.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -37,19 +38,21 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture {
public:
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
ownJID = JID("foo@fum.com/bum");
stanzaChannel = new DummyStanzaChannel();
stanzaChannel->setAvailable(true);
iqRouter = new IQRouter(stanzaChannel);
mucRegistry = new DummyMUCRegistry();
avatarStorage = new AvatarMemoryStorage();
- vcardStorage = new VCardMemoryStorage();
+ vcardStorage = new VCardMemoryStorage(crypto.get());
vcardManager = new VCardManager(ownJID, iqRouter, vcardStorage);
avatar1 = createByteArray("abcdefg");
- avatar1Hash = Hexify::hexify(SHA1::getHash(avatar1));
+ avatar1Hash = Hexify::hexify(crypto->getSHA1Hash(avatar1));
user1 = JID("user1@bar.com/bla");
user2 = JID("user2@foo.com/baz");
}
+
void tearDown() {
delete vcardManager;
@@ -113,7 +116,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture {
vcardManager->requestVCard(JID("foo@bar.com"));
stanzaChannel->onIQReceived(createVCardResult(ByteArray()));
- CPPUNIT_ASSERT(!avatarStorage->hasAvatar(Hexify::hexify(SHA1::getHash(ByteArray()))));
+ CPPUNIT_ASSERT(!avatarStorage->hasAvatar(Hexify::hexify(crypto->getSHA1Hash(ByteArray()))));
CPPUNIT_ASSERT_EQUAL(std::string(), testling->getAvatarHash(JID("foo@bar.com")));
}
@@ -150,7 +153,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<VCardUpdateAvatarManager> createManager() {
- boost::shared_ptr<VCardUpdateAvatarManager> result(new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry));
+ boost::shared_ptr<VCardUpdateAvatarManager> result(new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, crypto.get(), mucRegistry));
result->onAvatarChanged.connect(boost::bind(&VCardUpdateAvatarManagerTest::handleAvatarChanged, this, _1));
return result;
}
@@ -192,6 +195,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture {
std::vector<JID> changes;
JID user1;
JID user2;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateAvatarManagerTest);
diff --git a/Swiften/Avatars/VCardAvatarManager.cpp b/Swiften/Avatars/VCardAvatarManager.cpp
index ef1d293..8212a6e 100644
--- a/Swiften/Avatars/VCardAvatarManager.cpp
+++ b/Swiften/Avatars/VCardAvatarManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,7 +9,7 @@
#include <boost/bind.hpp>
#include <Swiften/Elements/VCard.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/Avatars/AvatarStorage.h>
#include <Swiften/MUC/MUCRegistry.h>
@@ -18,7 +18,7 @@
namespace Swift {
-VCardAvatarManager::VCardAvatarManager(VCardManager* vcardManager, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), avatarStorage_(avatarStorage), mucRegistry_(mucRegistry) {
+VCardAvatarManager::VCardAvatarManager(VCardManager* vcardManager, AvatarStorage* avatarStorage, CryptoProvider* crypto, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), avatarStorage_(avatarStorage), crypto_(crypto), mucRegistry_(mucRegistry) {
vcardManager_->onVCardChanged.connect(boost::bind(&VCardAvatarManager::handleVCardChanged, this, _1));
}
@@ -36,7 +36,7 @@ std::string VCardAvatarManager::getAvatarHash(const JID& jid) const {
if (!avatarStorage_->hasAvatar(hash)) {
VCard::ref vCard = vcardManager_->getVCard(avatarJID);
if (vCard) {
- std::string newHash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ std::string newHash = Hexify::hexify(crypto_->getSHA1Hash(vCard->getPhoto()));
if (newHash != hash) {
// Shouldn't happen, but sometimes seem to. Might be fixed if we
// move to a safer backend.
diff --git a/Swiften/Avatars/VCardAvatarManager.h b/Swiften/Avatars/VCardAvatarManager.h
index ed2ba5d..9c6943e 100644
--- a/Swiften/Avatars/VCardAvatarManager.h
+++ b/Swiften/Avatars/VCardAvatarManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -14,10 +14,11 @@ namespace Swift {
class MUCRegistry;
class AvatarStorage;
class VCardManager;
+ class CryptoProvider;
class SWIFTEN_API VCardAvatarManager : public AvatarProvider {
public:
- VCardAvatarManager(VCardManager*, AvatarStorage*, MUCRegistry* = NULL);
+ VCardAvatarManager(VCardManager*, AvatarStorage*, CryptoProvider* crypto, MUCRegistry* = NULL);
std::string getAvatarHash(const JID&) const;
@@ -28,6 +29,7 @@ namespace Swift {
private:
VCardManager* vcardManager_;
AvatarStorage* avatarStorage_;
+ CryptoProvider* crypto_;
MUCRegistry* mucRegistry_;
};
}
diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp
index 3c086d5..adbefd5 100644
--- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp
+++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp
@@ -11,7 +11,7 @@
#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Elements/VCardUpdate.h>
#include <Swiften/VCards/GetVCardRequest.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/Avatars/AvatarStorage.h>
#include <Swiften/MUC/MUCRegistry.h>
@@ -20,7 +20,7 @@
namespace Swift {
-VCardUpdateAvatarManager::VCardUpdateAvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), avatarStorage_(avatarStorage), mucRegistry_(mucRegistry) {
+VCardUpdateAvatarManager::VCardUpdateAvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, CryptoProvider* crypto, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), avatarStorage_(avatarStorage), crypto_(crypto), mucRegistry_(mucRegistry) {
stanzaChannel->onPresenceReceived.connect(boost::bind(&VCardUpdateAvatarManager::handlePresenceReceived, this, _1));
stanzaChannel->onAvailableChanged.connect(boost::bind(&VCardUpdateAvatarManager::handleStanzaChannelAvailableChanged, this, _1));
vcardManager_->onVCardChanged.connect(boost::bind(&VCardUpdateAvatarManager::handleVCardChanged, this, _1, _2));
@@ -54,7 +54,7 @@ void VCardUpdateAvatarManager::handleVCardChanged(const JID& from, VCard::ref vC
setAvatarHash(from, "");
}
else {
- std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ std::string hash = Hexify::hexify(crypto_->getSHA1Hash(vCard->getPhoto()));
if (!avatarStorage_->hasAvatar(hash)) {
avatarStorage_->addAvatar(hash, vCard->getPhoto());
}
diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.h b/Swiften/Avatars/VCardUpdateAvatarManager.h
index 43e1d62..3409f99 100644
--- a/Swiften/Avatars/VCardUpdateAvatarManager.h
+++ b/Swiften/Avatars/VCardUpdateAvatarManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -21,10 +21,11 @@ namespace Swift {
class AvatarStorage;
class StanzaChannel;
class VCardManager;
+ class CryptoProvider;
class SWIFTEN_API VCardUpdateAvatarManager : public AvatarProvider, public boost::bsignals::trackable {
public:
- VCardUpdateAvatarManager(VCardManager*, StanzaChannel*, AvatarStorage*, MUCRegistry* = NULL);
+ VCardUpdateAvatarManager(VCardManager*, StanzaChannel*, AvatarStorage*, CryptoProvider* crypto, MUCRegistry* = NULL);
std::string getAvatarHash(const JID&) const;
@@ -38,6 +39,7 @@ namespace Swift {
private:
VCardManager* vcardManager_;
AvatarStorage* avatarStorage_;
+ CryptoProvider* crypto_;
MUCRegistry* mucRegistry_;
std::map<JID, std::string> avatarHashes_;
};