summaryrefslogtreecommitdiff
path: root/algparam.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-03-25 16:38:42 -0400
committerJeffrey Walton <noloader@gmail.com>2017-03-25 16:38:42 -0400
commit0e55f5ac7d98f3c852ace7b4622f40cfa60b629f (patch)
tree350439fd5f1d5a2b43b4be0e55fe9a572b533a8d /algparam.h
parent6c50a99254bcb76fb9b2b476b392bbfe2259f409 (diff)
downloadcryptopp-git-0e55f5ac7d98f3c852ace7b4622f40cfa60b629f.tar.gz
Remove g_pAssignIntToInteger pointer, add CRYPTOPP_NO_ASSIGN_TO_INTEGER (Issue 389)
This effectively decouples Integer and Public Key from the rest of the library. The change means a compile time define is used rather than a runtime pointer. It avoids the race with Issue 389. The Public Key algorithms will fail if you use them. For example, running the self tests with CRYPTOPP_NO_ASSIGN_TO_INTEGER in effect results in "CryptoPP::Exception caught: NameValuePairs: type mismatch for 'EquivalentTo', stored 'i', trying to retrieve 'N8CryptoPP7IntegerE'". The exception is expected, and the same happend when g_pAssignIntToInteger was present.
Diffstat (limited to 'algparam.h')
-rw-r--r--algparam.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/algparam.h b/algparam.h
index 9e274f49..c66fe984 100644
--- a/algparam.h
+++ b/algparam.h
@@ -298,9 +298,11 @@ AssignFromHelperClass<T, T> AssignFromHelper(T *pObject, const NameValuePairs &s
// ********************************************************
-// to allow the linker to discard Integer code if not needed.
-typedef bool (CRYPTOPP_API * PAssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt);
-CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger;
+#ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER
+// Allow the linker to discard Integer code if not needed.
+// Also see http://github.com/weidai11/cryptopp/issues/389.
+bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const void *pInt);
+#endif
CRYPTOPP_DLL const std::type_info & CRYPTOPP_API IntegerTypeId();
@@ -386,8 +388,10 @@ public:
void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const
{
- // special case for retrieving an Integer parameter when an int was passed in
- if (!(g_pAssignIntToInteger != NULLPTR && typeid(T) == typeid(int) && g_pAssignIntToInteger(valueType, pValue, &m_value)))
+#ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER
+ // Special case for retrieving an Integer parameter when an int was passed in
+ if (!(typeid(T) == typeid(int) && AssignIntToInteger(valueType, pValue, &m_value)))
+#endif
{
NameValuePairs::ThrowIfTypeMismatch(name, typeid(T), valueType);
*reinterpret_cast<T *>(pValue) = m_value;