6 #ifndef CRYPTOPP_ALGPARAM_H 7 #define CRYPTOPP_ALGPARAM_H 29 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
31 Assign(reinterpret_cast<const byte *>(data), data ? strlen(data) : 0, deepCopy);
41 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
43 Assign(data, size, deepCopy);
53 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
56 Assign(reinterpret_cast<const byte *>(&
string[0]),
string.size(), deepCopy);
65 void Assign(
const byte *data,
size_t size,
bool deepCopy)
70 m_block.Assign(data, size);
76 m_deepCopy = deepCopy;
80 const byte *
begin()
const {
return m_deepCopy ? m_block.begin() : m_data;}
82 const byte *
end()
const {
return m_deepCopy ? m_block.end() : m_data + m_size;}
84 size_t size()
const {
return m_deepCopy ? m_block.size() : m_size;}
101 : m_data(data), m_size(
size) {}
106 : m_data(block.
begin()), m_size(block.
size()) {}
109 byte *
begin()
const {
return m_data;}
111 byte *
end()
const {
return m_data + m_size;}
113 size_t size()
const {
return m_size;}
131 : m_pairs1(pairs1), m_pairs2(pairs2) {}
133 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
139 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 140 template <
class T,
class BASE>
141 class GetValueHelperClass
144 GetValueHelperClass(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst)
145 : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(false), m_getValueNames(false)
147 if (strcmp(m_name,
"ValueNames") == 0)
149 m_found = m_getValueNames =
true;
153 if (
typeid(T) !=
typeid(BASE))
154 pObject->BASE::GetVoidValue(m_name, valueType, pValue);
155 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisPointer:") +=
typeid(T).name()) +=
';';
158 if (!m_found && strncmp(m_name,
"ThisPointer:", 12) == 0 && strcmp(m_name+12,
typeid(T).name()) == 0)
161 *
reinterpret_cast<const T **
>(pValue) = pObject;
166 if (!m_found && searchFirst)
167 m_found = searchFirst->
GetVoidValue(m_name, valueType, pValue);
169 if (!m_found &&
typeid(T) !=
typeid(BASE))
170 m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue);
173 operator bool()
const {
return m_found;}
176 GetValueHelperClass<T,BASE> & operator()(
const char *name,
const R & (T::*pm)()
const)
179 (*
reinterpret_cast<std::string *
>(m_pValue) += name) +=
";";
180 if (!m_found && strcmp(name, m_name) == 0)
183 *
reinterpret_cast<R *
>(m_pValue) = (m_pObject->*pm)();
189 GetValueHelperClass<T,BASE> &Assignable()
191 #ifndef __INTEL_COMPILER // ICL 9.1 workaround: Intel compiler copies the vTable pointer for some reason 193 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisObject:") +=
typeid(T).name()) +=
';';
194 if (!m_found && strncmp(m_name,
"ThisObject:", 11) == 0 && strcmp(m_name+11,
typeid(T).name()) == 0)
197 *
reinterpret_cast<T *
>(m_pValue) = *m_pObject;
207 const std::type_info *m_valueType;
209 bool m_found, m_getValueNames;
212 template <
class BASE,
class T>
213 GetValueHelperClass<T, BASE> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULLPTR)
215 return GetValueHelperClass<T, BASE>(pObject, name, valueType, pValue, searchFirst);
219 GetValueHelperClass<T, T> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULLPTR)
221 return GetValueHelperClass<T, T>(pObject, name, valueType, pValue, searchFirst);
226 template <
class T,
class BASE>
227 class AssignFromHelperClass
231 : m_pObject(pObject), m_source(source), m_done(false)
235 else if (
typeid(BASE) !=
typeid(T))
236 pObject->BASE::AssignFrom(source);
240 AssignFromHelperClass & operator()(
const char *name,
void (T::*pm)(
const R&))
245 if (!m_source.GetValue(name, value))
246 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
247 (m_pObject->*pm)(value);
252 template <
class R,
class S>
253 AssignFromHelperClass & operator()(
const char *name1,
const char *name2,
void (T::*pm)(
const R&,
const S&))
258 if (!m_source.GetValue(name1, value1))
259 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
261 if (!m_source.GetValue(name2, value2))
262 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
263 (m_pObject->*pm)(value1, value2);
274 template <
class BASE,
class T>
275 AssignFromHelperClass<T, BASE> AssignFromHelper(T *pObject,
const NameValuePairs &source)
277 return AssignFromHelperClass<T, BASE>(pObject, source);
281 AssignFromHelperClass<T, T> AssignFromHelper(T *pObject,
const NameValuePairs &source)
283 return AssignFromHelperClass<T, T>(pObject, source);
286 #endif // CRYPTOPP_DOXYGEN_PROCESSING 290 #ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER 293 CRYPTOPP_DLL
bool AssignIntToInteger(
const std::type_info &valueType,
void *pInteger,
const void *pInt);
296 CRYPTOPP_DLL
const std::type_info & CRYPTOPP_API IntegerTypeId();
306 ParameterNotUsed(
const char *name) :
Exception(OTHER_ERROR, std::string(
"AlgorithmParametersBase: parameter \"") + name +
"\" not used") {}
312 #if defined(CRYPTOPP_CXX17_EXCEPTIONS) 313 if (std::uncaught_exceptions() == 0)
314 #elif defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) 315 if (std::uncaught_exception() ==
false)
320 if (m_throwIfNotUsed && !m_used)
323 #if !defined(CRYPTOPP_CXX17_EXCEPTIONS) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) 332 : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used)
334 m_next.reset(const_cast<AlgorithmParametersBase &>(x).m_next.release());
344 : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(false) {}
346 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
352 virtual void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
353 virtual void MoveInto(
void *p)
const =0;
356 bool m_throwIfNotUsed;
378 void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const 380 #ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER 382 if (!(
typeid(T) ==
typeid(
int) && AssignIntToInteger(valueType, pValue, &m_value)))
386 *
reinterpret_cast<T *
>(pValue) = m_value;
390 #if defined(DEBUG_NEW) && (_MSC_VER >= 1300) 391 # pragma push_macro("new") 395 void MoveInto(
void *buffer)
const 401 #if defined(DEBUG_NEW) && (_MSC_VER >= 1300) 402 # pragma pop_macro("new") 446 , m_defaultThrowIfNotUsed(throwIfNotUsed)
463 p->m_next.reset(m_next.release());
464 m_next.reset(p.release());
465 m_defaultThrowIfNotUsed = throwIfNotUsed;
476 return operator()(name, value, m_defaultThrowIfNotUsed);
479 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
483 bool m_defaultThrowIfNotUsed;
508 #define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) 509 #define CRYPTOPP_SET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Set##name) 510 #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 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.
Interface for retrieving values given their names.
byte * end() const
Pointer beyond the last byte in the memory block.