summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Crypto/OpenSSLCryptoProvider.cpp')
-rw-r--r--Swiften/Crypto/OpenSSLCryptoProvider.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/Swiften/Crypto/OpenSSLCryptoProvider.cpp b/Swiften/Crypto/OpenSSLCryptoProvider.cpp
index c785041..5245bd8 100644
--- a/Swiften/Crypto/OpenSSLCryptoProvider.cpp
+++ b/Swiften/Crypto/OpenSSLCryptoProvider.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2013 Isode Limited.
+ * Copyright (c) 2013-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Crypto/OpenSSLCryptoProvider.h>
#include <openssl/sha.h>
#include <openssl/md5.h>
#include <openssl/hmac.h>
@@ -22,30 +22,30 @@ using namespace Swift;
namespace {
class SHA1Hash : public Hash {
public:
SHA1Hash() : finalized(false) {
if (!SHA1_Init(&context)) {
assert(false);
}
}
- ~SHA1Hash() {
+ ~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(SHA_DIGEST_LENGTH);
SHA1_Final(vecptr(result), &context);
return result;
}
private:
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
@@ -63,30 +63,30 @@ namespace {
class MD5Hash : public Hash {
public:
MD5Hash() : finalized(false) {
if (!MD5_Init(&context)) {
assert(false);
}
}
- ~MD5Hash() {
+ ~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(MD5_DIGEST_LENGTH);
MD5_Final(vecptr(result), &context);
return result;
}
private:
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
@@ -101,19 +101,24 @@ namespace {
MD5_CTX context;
bool finalized;
};
template<typename T>
ByteArray getHMACSHA1Internal(const T& key, const ByteArray& data) {
unsigned int len = SHA_DIGEST_LENGTH;
std::vector<unsigned char> result(len);
- HMAC(EVP_sha1(), vecptr(key), boost::numeric_cast<int>(key.size()), vecptr(data), data.size(), vecptr(result), &len);
+ try {
+ HMAC(EVP_sha1(), vecptr(key), boost::numeric_cast<int>(key.size()), vecptr(data), data.size(), vecptr(result), &len);
+ }
+ catch (const boost::numeric::bad_numeric_cast&) {
+ assert(false);
+ }
return result;
}
}
OpenSSLCryptoProvider::OpenSSLCryptoProvider() {
}
OpenSSLCryptoProvider::~OpenSSLCryptoProvider() {
}