summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-04-27 15:30:27 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-27 15:30:27 (GMT)
commit87d5557ecba47f0cfd323e79f7d9284c484f825a (patch)
tree7af755e30a37dd388392e305b9c01637d8a039cb /Swiften/Crypto/CommonCryptoCryptoProvider.cpp
parent860d265a878ca444fca358f468a32df32a7f4444 (diff)
downloadswift-87d5557ecba47f0cfd323e79f7d9284c484f825a.zip
swift-87d5557ecba47f0cfd323e79f7d9284c484f825a.tar.bz2
Make HMACSHA1 not be a Hash.
Change-Id: I798d468614d2285c6f77640c365b51b19df2bf73
Diffstat (limited to 'Swiften/Crypto/CommonCryptoCryptoProvider.cpp')
-rw-r--r--Swiften/Crypto/CommonCryptoCryptoProvider.cpp50
1 files changed, 9 insertions, 41 deletions
diff --git a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
index f1810ba..14f9284 100644
--- a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
+++ b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
@@ -100,42 +100,11 @@ namespace {
};
template<typename T>
- class HMACHash : public Hash {
- public:
- HMACHash(const T& key) : finalized(false) {
- CCHmacInit(&context, kCCHmacAlgSHA1, vecptr(key), key.size());
- }
-
- ~HMACHash() {
- }
-
- virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE {
- return updateInternal(data);
- }
-
- virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE {
- return updateInternal(data);
- }
-
- virtual std::vector<unsigned char> getHash() {
- assert(!finalized);
- std::vector<unsigned char> result(CC_SHA1_DIGEST_LENGTH);
- CCHmacFinal(&context, vecptr(result));
- return result;
- }
-
- private:
- template<typename ContainerType>
- Hash& updateInternal(const ContainerType& data) {
- assert(!finalized);
- CCHmacUpdate(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()));
- return *this;
- }
-
- private:
- CCHmacContext context;
- bool finalized;
- };
+ ByteArray getHMACSHA1Internal(const T& key, const ByteArray& data) {
+ std::vector<unsigned char> result(CC_SHA1_DIGEST_LENGTH);
+ CCHmac(kCCHmacAlgSHA1, vecptr(key), key.size(), vecptr(data), boost::numeric_cast<CC_LONG>(data.size()), vecptr(result));
+ return result;
+ }
}
CommonCryptoCryptoProvider::CommonCryptoCryptoProvider() {
@@ -152,15 +121,14 @@ Hash* CommonCryptoCryptoProvider::createMD5() {
return new MD5Hash();
}
-Hash* CommonCryptoCryptoProvider::createHMACSHA1(const SafeByteArray& key) {
- return new HMACHash<SafeByteArray>(key);
+ByteArray CommonCryptoCryptoProvider::getHMACSHA1(const SafeByteArray& key, const ByteArray& data) {
+ return getHMACSHA1Internal(key, data);
}
-Hash* CommonCryptoCryptoProvider::createHMACSHA1(const ByteArray& key) {
- return new HMACHash<ByteArray>(key);
+ByteArray CommonCryptoCryptoProvider::getHMACSHA1(const ByteArray& key, const ByteArray& data) {
+ return getHMACSHA1Internal(key, data);
}
-
bool CommonCryptoCryptoProvider::isMD5AllowedForCrypto() const {
return true;
}