8 #ifndef CRYPTOPP_ALGPARAM_H 9 #define CRYPTOPP_ALGPARAM_H 15 #if (CRYPTOPP_MSC_VERSION >= 1400) 16 # pragma warning(push) 17 # pragma warning(disable: 6011 28193) 38 : m_deepCopy(false), m_data(NULL), m_size(0)
40 Assign((
const byte *)data, data ? strlen(data) : 0, deepCopy);
50 : m_deepCopy(false), m_data(NULL), m_size(0)
52 Assign(data, size, deepCopy);
62 : m_deepCopy(false), m_data(NULL), m_size(0)
65 Assign((
const byte *)
string.data(),
string.size(), deepCopy);
74 void Assign(
const byte *data,
size_t size,
bool deepCopy)
79 m_block.Assign(data, size);
85 m_deepCopy = deepCopy;
89 const byte *
begin()
const {
return m_deepCopy ? m_block.begin() : m_data;}
91 const byte *
end()
const {
return m_deepCopy ? m_block.end() : m_data + m_size;}
93 size_t size()
const {
return m_deepCopy ? m_block.size() : m_size;}
111 : m_data(data), m_size(
size) {}
116 : m_data(block.
begin()), m_size(block.
size()) {}
119 byte *
begin()
const {
return m_data;}
121 byte *
end()
const {
return m_data + m_size;}
123 size_t size()
const {
return m_size;}
142 : m_pairs1(pairs1), m_pairs2(pairs2) {}
144 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
150 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 151 template <
class T,
class BASE>
152 class GetValueHelperClass
155 GetValueHelperClass(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst)
156 : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(
false), m_getValueNames(
false)
158 if (strcmp(m_name,
"ValueNames") == 0)
160 m_found = m_getValueNames =
true;
164 if (
typeid(T) !=
typeid(BASE))
165 pObject->BASE::GetVoidValue(m_name, valueType, pValue);
166 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisPointer:") +=
typeid(T).name()) +=
';';
169 if (!m_found && strncmp(m_name,
"ThisPointer:", 12) == 0 && strcmp(m_name+12,
typeid(T).name()) == 0)
172 *
reinterpret_cast<const T **
>(pValue) = pObject;
177 if (!m_found && searchFirst)
178 m_found = searchFirst->
GetVoidValue(m_name, valueType, pValue);
180 if (!m_found &&
typeid(T) !=
typeid(BASE))
181 m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue);
184 operator bool()
const {
return m_found;}
187 GetValueHelperClass<T,BASE> & operator()(
const char *name,
const R & (T::*pm)()
const)
190 (*
reinterpret_cast<std::string *
>(m_pValue) += name) +=
";";
191 if (!m_found && strcmp(name, m_name) == 0)
194 *
reinterpret_cast<R *
>(m_pValue) = (m_pObject->*pm)();
200 GetValueHelperClass<T,BASE> &Assignable()
202 #ifndef __INTEL_COMPILER // ICL 9.1 workaround: Intel compiler copies the vTable pointer for some reason 204 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisObject:") +=
typeid(T).name()) +=
';';
205 if (!m_found && strncmp(m_name,
"ThisObject:", 11) == 0 && strcmp(m_name+11,
typeid(T).name()) == 0)
208 *
reinterpret_cast<T *
>(m_pValue) = *m_pObject;
218 const std::type_info *m_valueType;
220 bool m_found, m_getValueNames;
223 template <
class BASE,
class T>
224 GetValueHelperClass<T, BASE> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULL, BASE *dummy=NULL)
226 CRYPTOPP_UNUSED(dummy);
227 return GetValueHelperClass<T, BASE>(pObject, name, valueType, pValue, searchFirst);
231 GetValueHelperClass<T, T> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULL)
233 return GetValueHelperClass<T, T>(pObject, name, valueType, pValue, searchFirst);
239 #if defined(_MSC_VER) && (_MSC_VER < 1300) 241 R Hack_DefaultValueFromConstReferenceType(
const R &)
247 bool Hack_GetValueIntoConstReference(
const NameValuePairs &source,
const char *name,
const R &value)
249 return source.
GetValue(name, const_cast<R &>(value));
252 template <
class T,
class BASE>
253 class AssignFromHelperClass
257 : m_pObject(pObject), m_source(source), m_done(
false)
261 else if (
typeid(BASE) !=
typeid(T))
262 pObject->BASE::AssignFrom(source);
266 AssignFromHelperClass & operator()(
const char *name,
void (T::*pm)(R))
270 R value = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<R>(*(
int *)NULL));
271 if (!Hack_GetValueIntoConstReference(m_source, name, value))
272 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
273 (m_pObject->*pm)(value);
278 template <
class R,
class S>
279 AssignFromHelperClass & operator()(
const char *name1,
const char *name2,
void (T::*pm)(R, S))
283 R value1 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<R>(*(
int *)NULL));
284 if (!Hack_GetValueIntoConstReference(m_source, name1, value1))
285 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
286 S value2 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<S>(*(
int *)NULL));
287 if (!Hack_GetValueIntoConstReference(m_source, name2, value2))
288 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
289 (m_pObject->*pm)(value1, value2);
300 template <
class T,
class BASE>
301 class AssignFromHelperClass
305 : m_pObject(pObject), m_source(source), m_done(
false)
309 else if (
typeid(BASE) !=
typeid(T))
310 pObject->BASE::AssignFrom(source);
314 AssignFromHelperClass & operator()(
const char *name,
void (T::*pm)(
const R&))
319 if (!m_source.GetValue(name, value))
320 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
321 (m_pObject->*pm)(value);
326 template <
class R,
class S>
327 AssignFromHelperClass & operator()(
const char *name1,
const char *name2,
void (T::*pm)(
const R&,
const S&))
332 if (!m_source.GetValue(name1, value1))
333 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
335 if (!m_source.GetValue(name2, value2))
336 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
337 (m_pObject->*pm)(value1, value2);
349 template <
class BASE,
class T>
350 AssignFromHelperClass<T, BASE> AssignFromHelper(T *pObject,
const NameValuePairs &source, BASE *dummy=NULL)
352 CRYPTOPP_UNUSED(dummy);
353 return AssignFromHelperClass<T, BASE>(pObject, source);
357 AssignFromHelperClass<T, T> AssignFromHelper(T *pObject,
const NameValuePairs &source)
359 return AssignFromHelperClass<T, T>(pObject, source);
362 #endif // CRYPTOPP_DOXYGEN_PROCESSING 367 typedef bool (CRYPTOPP_API * PAssignIntToInteger)(
const std::type_info &valueType,
void *pInteger,
const void *pInt);
368 CRYPTOPP_DLL
extern PAssignIntToInteger g_pAssignIntToInteger;
370 CRYPTOPP_DLL
const std::type_info & CRYPTOPP_API IntegerTypeId();
382 ParameterNotUsed(
const char *name) :
Exception(OTHER_ERROR, std::string(
"AlgorithmParametersBase: parameter \"") + name +
"\" not used") {}
387 : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used)
389 m_next.reset(const_cast<AlgorithmParametersBase &>(x).m_next.release());
399 : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(false) {}
403 #ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 404 if (!std::uncaught_exception())
409 if (m_throwIfNotUsed && !m_used)
412 #ifndef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 419 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
425 virtual void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
426 virtual void MoveInto(
void *p)
const =0;
429 bool m_throwIfNotUsed;
452 void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const 455 if (!(g_pAssignIntToInteger != NULL &&
typeid(T) ==
typeid(
int) && g_pAssignIntToInteger(valueType, pValue, &m_value)))
458 *
reinterpret_cast<T *
>(pValue) = m_value;
462 #if defined(DEBUG_NEW) && (_MSC_VER >= 1300) 463 # pragma push_macro("new") 467 void MoveInto(
void *buffer)
const 473 #if defined(DEBUG_NEW) && (_MSC_VER >= 1300) 474 # pragma pop_macro("new") 507 , m_defaultThrowIfNotUsed(throwIfNotUsed)
524 p->m_next.reset(m_next.release());
525 m_next.reset(p.release());
526 m_defaultThrowIfNotUsed = throwIfNotUsed;
537 return operator()(name, value, m_defaultThrowIfNotUsed);
540 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
544 bool m_defaultThrowIfNotUsed;
569 #define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) 570 #define CRYPTOPP_SET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Set##name) 571 #define CRYPTOPP_SET_FUNCTION_ENTRY2(name1, name2) (Name::name1(), Name::name2(), &ThisClass::Set##name1##And##name2) 574 #if (CRYPTOPP_MSC_VERSION >= 1400) 575 # pragma warning(pop) Used to pass byte array input as part of a NameValuePairs object.
Base class for all exceptions thrown by the library.
An invalid argument was detected.
CombinedNameValuePairs(const NameValuePairs &pairs1, const NameValuePairs &pairs2)
Construct a CombinedNameValuePairs.
Utility functions for the Crypto++ library.
Base class for AlgorithmParameters.
size_t size() const
Length of the memory block.
size_t size() const
Length of the memory block.
ConstByteArrayParameter(const T &string, bool deepCopy=false)
Construct a ConstByteArrayParameter.
AlgorithmParametersBase(const char *name, bool throwIfNotUsed)
Construct a AlgorithmParametersBase.
ConstByteArrayParameter(const byte *data, size_t size, bool deepCopy=false)
Construct a ConstByteArrayParameter.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
Library configuration file.
ConstByteArrayParameter(const char *data=NULL, bool deepCopy=false)
Construct a ConstByteArrayParameter.
Combines two sets of NameValuePairs.
Used to pass byte array input as part of a NameValuePairs object.
Classes and functions for secure memory allocations.
const byte * begin() const
Pointer to the first byte in the memory block.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
Exception thrown when an AlgorithmParameter is unused.
void Assign(const byte *data, size_t size, bool deepCopy)
Assign contents from a memory buffer.
const byte * end() const
Pointer beyond the last byte in the memory block.
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
Template base class for AlgorithmParameters.
AlgorithmParameters & operator()(const char *name, const T &value)
Appends a NameValuePair to a collection of NameValuePairs.
ByteArrayParameter(byte *data=NULL, unsigned int size=0)
Construct a ByteArrayParameter.
ByteArrayParameter(SecByteBlock &block)
Construct a ByteArrayParameter.
static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
Ensures an expected name and type is present.
AlgorithmParameters & operator()(const char *name, const T &value, bool throwIfNotUsed)
byte * begin() const
Pointer to the first byte in the memory block.
An object that implements NameValuePairs.
Multiple precision integer with arithmetic operations.
AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed)
Construct an AlgorithmParametersTemplate.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
Interface for retrieving values given their names.
byte * end() const
Pointer beyond the last byte in the memory block.