8 #ifndef CRYPTOPP_ALGPARAM_H 9 #define CRYPTOPP_ALGPARAM_H 15 #if CRYPTOPP_MSC_VERSION 16 # pragma warning(push) 17 # pragma warning(disable: 6011 28193) 33 ConstByteArrayParameter(
const char *data = NULL,
bool deepCopy =
false)
34 : m_deepCopy(
false), m_data(NULL), m_size(0)
36 Assign((
const byte *)data, data ? strlen(data) : 0, deepCopy);
38 ConstByteArrayParameter(
const byte *data,
size_t size,
bool deepCopy =
false)
39 : m_deepCopy(
false), m_data(NULL), m_size(0)
41 Assign(data, size, deepCopy);
43 template <
class T> ConstByteArrayParameter(
const T &
string,
bool deepCopy =
false)
44 : m_deepCopy(
false), m_data(NULL), m_size(0)
47 Assign((
const byte *)
string.data(),
string.size(), deepCopy);
50 void Assign(
const byte *data,
size_t size,
bool deepCopy)
55 m_block.Assign(data, size);
61 m_deepCopy = deepCopy;
64 const byte *begin()
const {
return m_deepCopy ? m_block.begin() : m_data;}
65 const byte *end()
const {
return m_deepCopy ? m_block.end() : m_data + m_size;}
66 size_t size()
const {
return m_deepCopy ? m_block.size() : m_size;}
79 : m_data(data), m_size(size) {}
81 : m_data(block.
begin()), m_size(block.
size()) {}
83 byte *begin()
const {
return m_data;}
84 byte *end()
const {
return m_data + m_size;}
85 size_t size()
const {
return m_size;}
96 : m_pairs1(pairs1), m_pairs2(pairs2) {}
98 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
104 template <
class T,
class BASE>
109 : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(
false), m_getValueNames(
false)
111 if (strcmp(m_name,
"ValueNames") == 0)
113 m_found = m_getValueNames =
true;
117 if (
typeid(T) !=
typeid(BASE))
118 pObject->BASE::GetVoidValue(m_name, valueType, pValue);
119 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisPointer:") +=
typeid(T).name()) +=
';';
122 if (!m_found && strncmp(m_name,
"ThisPointer:", 12) == 0 && strcmp(m_name+12,
typeid(T).name()) == 0)
125 *
reinterpret_cast<const T **
>(pValue) = pObject;
130 if (!m_found && searchFirst)
131 m_found = searchFirst->
GetVoidValue(m_name, valueType, pValue);
133 if (!m_found &&
typeid(T) !=
typeid(BASE))
134 m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue);
137 operator bool()
const {
return m_found;}
143 (*
reinterpret_cast<std::string *
>(m_pValue) += name) +=
";";
144 if (!m_found && strcmp(name, m_name) == 0)
147 *
reinterpret_cast<R *
>(m_pValue) = (m_pObject->*pm)();
155 #ifndef __INTEL_COMPILER // ICL 9.1 workaround: Intel compiler copies the vTable pointer for some reason 157 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisObject:") +=
typeid(T).name()) +=
';';
158 if (!m_found && strncmp(m_name,
"ThisObject:", 11) == 0 && strcmp(m_name+11,
typeid(T).name()) == 0)
161 *
reinterpret_cast<T *
>(m_pValue) = *m_pObject;
171 const std::type_info *m_valueType;
173 bool m_found, m_getValueNames;
176 template <
class BASE,
class T>
179 CRYPTOPP_UNUSED(dummy);
192 #if defined(_MSC_VER) && (_MSC_VER < 1300) 194 R Hack_DefaultValueFromConstReferenceType(
const R &)
200 bool Hack_GetValueIntoConstReference(
const NameValuePairs &source,
const char *name,
const R &value)
202 return source.
GetValue(name, const_cast<R &>(value));
205 template <
class T,
class BASE>
210 : m_pObject(pObject), m_source(source), m_done(
false)
214 else if (
typeid(BASE) !=
typeid(T))
215 pObject->BASE::AssignFrom(source);
223 R value = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<R>(*(
int *)NULL));
224 if (!Hack_GetValueIntoConstReference(m_source, name, value))
225 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
226 (m_pObject->*pm)(value);
231 template <
class R,
class S>
236 R value1 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<R>(*(
int *)NULL));
237 if (!Hack_GetValueIntoConstReference(m_source, name1, value1))
238 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
239 S value2 = Hack_DefaultValueFromConstReferenceType(reinterpret_cast<S>(*(
int *)NULL));
240 if (!Hack_GetValueIntoConstReference(m_source, name2, value2))
241 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
242 (m_pObject->*pm)(value1, value2);
253 template <
class T,
class BASE>
258 : m_pObject(pObject), m_source(source), m_done(
false)
262 else if (
typeid(BASE) !=
typeid(T))
263 pObject->BASE::AssignFrom(source);
272 if (!m_source.GetValue(name, value))
273 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
274 (m_pObject->*pm)(value);
279 template <
class R,
class S>
280 AssignFromHelperClass & operator()(
const char *name1,
const char *name2,
void (T::*pm)(
const R&,
const S&))
285 if (!m_source.GetValue(name1, value1))
286 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
288 if (!m_source.GetValue(name2, value2))
289 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
290 (m_pObject->*pm)(value1, value2);
302 template <
class BASE,
class T>
305 CRYPTOPP_UNUSED(dummy);
318 typedef bool (CRYPTOPP_API * PAssignIntToInteger)(
const std::type_info &valueType,
void *pInteger,
const void *pInt);
319 CRYPTOPP_DLL
extern PAssignIntToInteger g_pAssignIntToInteger;
321 CRYPTOPP_DLL
const std::type_info & CRYPTOPP_API IntegerTypeId();
329 ParameterNotUsed(
const char *name) :
Exception(OTHER_ERROR, std::string(
"AlgorithmParametersBase: parameter \"") + name +
"\" not used") {}
334 : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used)
336 m_next.reset(const_cast<AlgorithmParametersBase &>(x).m_next.release());
341 : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(
false) {}
345 #ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 346 if (!std::uncaught_exception())
351 if (m_throwIfNotUsed && !m_used)
354 #ifndef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 361 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
367 virtual void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
368 virtual void MoveInto(
void *p)
const =0;
371 bool m_throwIfNotUsed;
385 void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const 388 if (!(g_pAssignIntToInteger != NULL &&
typeid(T) ==
typeid(
int) && g_pAssignIntToInteger(valueType, pValue, &m_value)))
391 *
reinterpret_cast<T *
>(pValue) = m_value;
395 void MoveInto(
void *buffer)
const 431 , m_defaultThrowIfNotUsed(throwIfNotUsed)
448 p->m_next.reset(m_next.release());
449 m_next.reset(p.release());
450 m_defaultThrowIfNotUsed = throwIfNotUsed;
461 return operator()(name, value, m_defaultThrowIfNotUsed);
464 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
468 bool m_defaultThrowIfNotUsed;
493 #define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) 494 #define CRYPTOPP_SET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Set##name) 495 #define CRYPTOPP_SET_FUNCTION_ENTRY2(name1, name2) (Name::name1(), Name::name2(), &ThisClass::Set##name1##And##name2) used to pass byte array input as part of a NameValuePairs object
Base class for all exceptions thrown by Crypto++.
An invalid argument was detected.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
Utility functions for the Crypto++ library.
Abstract base classes that provide a uniform interface to this library.
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
size_type size() const
Provides the count of elements in the SecBlock.
Classes for automatic resource management.
Library configuration file.
SecByteBlock is a SecBlock<byte> typedef.
Classes and functions for secure memory allocations.
bool GetValue(const char *name, T &value) const
Get a named value.
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.
AlgorithmParameters & operator()(const char *name, const T &value)
Appends a NameValuePair to a collection of NameValuePairs.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
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)
An object that implements NameValuePairs.
Crypto++ library namespace.
Interface for retrieving values given their names.