summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp')
-rw-r--r--Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
index 6b53a1b..601a97f 100644
--- a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
+++ b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
@@ -4,17 +4,23 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+
#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h>
#include <Swiften/StringCodecs/Hexify.h>
-#include <Swiften/StringCodecs/MD5.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
namespace Swift {
-IncrementalBytestreamHashCalculator::IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1) {
- md5Hasher = doMD5 ? new MD5() : NULL;
- sha1Hasher = doSHA1 ? new SHA1() : NULL;
+IncrementalBytestreamHashCalculator::IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1, CryptoProvider* crypto) {
+ md5Hasher = doMD5 ? crypto->createMD5() : NULL;
+ sha1Hasher = doSHA1 ? crypto->createSHA1() : NULL;
}
IncrementalBytestreamHashCalculator::~IncrementalBytestreamHashCalculator() {
@@ -41,21 +47,19 @@ void IncrementalBytestreamHashCalculator::feedData(const SafeByteArray& data) {
}*/
std::string IncrementalBytestreamHashCalculator::getSHA1String() {
- if (sha1Hasher) {
- ByteArray result = sha1Hasher->getHash();
- return Hexify::hexify(result);
- } else {
- return std::string();
+ assert(sha1Hasher);
+ if (!sha1Hash) {
+ sha1Hash = Hexify::hexify(sha1Hasher->getHash());
}
+ return *sha1Hash;
}
std::string IncrementalBytestreamHashCalculator::getMD5String() {
- if (md5Hasher) {
- ByteArray result = md5Hasher->getHash();
- return Hexify::hexify(result);
- } else {
- return std::string();
+ assert(md5Hasher);
+ if (!md5Hash) {
+ md5Hash = Hexify::hexify(md5Hasher->getHash());
}
+ return *md5Hash;
}
}