summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Crypto/CommonCryptoCryptoProvider.cpp')
-rw-r--r--Swiften/Crypto/CommonCryptoCryptoProvider.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
index 9fbdb2a..3cc69b0 100644
--- a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
+++ b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2016 Isode Limited.
+ * Copyright (c) 2013-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -27,18 +27,18 @@ namespace {
}
}
- ~SHA1Hash() {
+ virtual ~SHA1Hash() override {
}
- virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const ByteArray& data) override {
return updateInternal(data);
}
- virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const SafeByteArray& data) override {
return updateInternal(data);
}
- virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE {
+ virtual std::vector<unsigned char> getHash() override {
assert(!finalized);
std::vector<unsigned char> result(CC_SHA1_DIGEST_LENGTH);
CC_SHA1_Final(vecptr(result), &context);
@@ -49,7 +49,12 @@ namespace {
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
assert(!finalized);
- if (!CC_SHA1_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) {
+ try {
+ if (!CC_SHA1_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) {
+ assert(false);
+ }
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
assert(false);
}
return *this;
@@ -68,18 +73,18 @@ namespace {
}
}
- ~MD5Hash() {
+ virtual ~MD5Hash() override {
}
- virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const ByteArray& data) override {
return updateInternal(data);
}
- virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const SafeByteArray& data) override {
return updateInternal(data);
}
- virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE {
+ virtual std::vector<unsigned char> getHash() override {
assert(!finalized);
std::vector<unsigned char> result(CC_MD5_DIGEST_LENGTH);
CC_MD5_Final(vecptr(result), &context);
@@ -90,7 +95,12 @@ namespace {
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
assert(!finalized);
- if (!CC_MD5_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) {
+ try {
+ if (!CC_MD5_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) {
+ assert(false);
+ }
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
assert(false);
}
return *this;
@@ -104,7 +114,12 @@ namespace {
template<typename T>
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));
+ try {
+ CCHmac(kCCHmacAlgSHA1, vecptr(key), key.size(), vecptr(data), boost::numeric_cast<CC_LONG>(data.size()), vecptr(result));
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
+ assert(false);
+ }
return result;
}
}