diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-27 02:22:14 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-04-27 02:22:14 +0000 |
| commit | 1ef99931e131343f069a4b74edfc06196d72d85b (patch) | |
| tree | d640f061a66a193d5f4d92b61836161208ccff14 /src/LibsslDHKeyExchange.h | |
| parent | a7952cce05a41c6e20d6eddc569a8bffe974aade (diff) | |
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten Exception class. Throw exception object, not its pointer and
catch by reference, so that remove problematic delete operator for
catched exception.
* src/Exception.cc
* src/Exception.h
* test/ExceptionTest.cc
* src/*: All files throwing/catching exception.
* test/*: All files throwing/catching exception.
Diffstat (limited to 'src/LibsslDHKeyExchange.h')
| -rw-r--r-- | src/LibsslDHKeyExchange.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/LibsslDHKeyExchange.h b/src/LibsslDHKeyExchange.h index 76f20ec3..bab473d3 100644 --- a/src/LibsslDHKeyExchange.h +++ b/src/LibsslDHKeyExchange.h @@ -37,6 +37,7 @@ #include "common.h" #include "DlAbortEx.h" +#include "StringFormat.h" #include <openssl/dh.h> #include <openssl/rand.h> #include <openssl/err.h> @@ -60,8 +61,9 @@ private: void handleError(const std::string& funName) const { - throw new DlAbortEx("Exception in libssl routine %s(DHKeyExchange class): %s", - funName.c_str(), ERR_error_string(ERR_get_error(), 0)); + throw DlAbortEx + (StringFormat("Exception in libssl routine %s(DHKeyExchange class): %s", + funName.c_str(), ERR_error_string(ERR_get_error(), 0)).str()); } public: DHKeyExchange():_bnCtx(0), @@ -120,15 +122,17 @@ public: size_t getPublicKey(unsigned char* out, size_t outLength) const { if(outLength < _keyLength) { - throw new DlAbortEx("Insufficient buffer for public key. expect:%u, actual:%u", - _keyLength, outLength); + throw DlAbortEx + (StringFormat("Insufficient buffer for public key. expect:%u, actual:%u", + _keyLength, outLength).str()); } memset(out, 0, outLength); size_t publicKeyBytes = BN_num_bytes(_publicKey); size_t offset = _keyLength-publicKeyBytes; size_t nwritten = BN_bn2bin(_publicKey, out+offset); if(nwritten != publicKeyBytes) { - throw new DlAbortEx("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, publicKeyBytes); + throw DlAbortEx + (StringFormat("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, publicKeyBytes).str()); } return nwritten; } @@ -145,8 +149,9 @@ public: size_t peerPublicKeyLength) const { if(outLength < _keyLength) { - throw new DlAbortEx("Insufficient buffer for secret. expect:%u, actual:%u", - _keyLength, outLength); + throw DlAbortEx + (StringFormat("Insufficient buffer for secret. expect:%u, actual:%u", + _keyLength, outLength).str()); } @@ -165,7 +170,8 @@ public: size_t nwritten = BN_bn2bin(secret, out+offset); BN_free(secret); if(nwritten != secretBytes) { - throw new DlAbortEx("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, secretBytes); + throw DlAbortEx + (StringFormat("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, secretBytes).str()); } return nwritten; } |
