6#ifndef CRYPTOPP_ALGPARAM_H
7#define CRYPTOPP_ALGPARAM_H
33 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
35 Assign(
reinterpret_cast<const byte *
>(data), data ? strlen(data) : 0, deepCopy);
45 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
47 Assign(data, size, deepCopy);
57 : m_deepCopy(false), m_data(NULLPTR), m_size(0)
60 Assign(
reinterpret_cast<const byte *
>(&
string[0]),
string.size(), deepCopy);
69 void Assign(
const byte *data,
size_t size,
bool deepCopy)
74 m_block.Assign(data, size);
80 m_deepCopy = deepCopy;
84 const byte *
begin()
const {
return m_deepCopy ? m_block.begin() : m_data;}
86 const byte *
end()
const {
return m_deepCopy ? m_block.end() : m_data + m_size;}
88 size_t size()
const {
return m_deepCopy ? m_block.size() : m_size;}
105 : m_data(data), m_size(
size) {}
110 : m_data(block.
begin()), m_size(block.
size()) {}
113 byte *
begin()
const {
return m_data;}
115 byte *
end()
const {
return m_data + m_size;}
117 size_t size()
const {
return m_size;}
135 : m_pairs1(pairs1), m_pairs2(pairs2) {}
137 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
143#ifndef CRYPTOPP_DOXYGEN_PROCESSING
144template <
class T,
class BASE>
145class GetValueHelperClass
148 GetValueHelperClass(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst)
149 : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(false), m_getValueNames(false)
151 if (strcmp(m_name,
"ValueNames") == 0)
153 m_found = m_getValueNames =
true;
157 if (
typeid(T) !=
typeid(BASE))
158 pObject->BASE::GetVoidValue(m_name, valueType, pValue);
159 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisPointer:") +=
typeid(T).name()) +=
';';
162 if (!m_found && strncmp(m_name,
"ThisPointer:", 12) == 0 && strcmp(m_name+12,
typeid(T).name()) == 0)
165 *
reinterpret_cast<const T **
>(pValue) = pObject;
170 if (!m_found && searchFirst)
171 m_found = searchFirst->
GetVoidValue(m_name, valueType, pValue);
173 if (!m_found &&
typeid(T) !=
typeid(BASE))
174 m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue);
177 operator bool()
const {
return m_found;}
180 GetValueHelperClass<T,BASE> & operator()(
const char *name,
const R & (T::*pm)()
const)
183 (*
reinterpret_cast<std::string *
>(m_pValue) += name) +=
";";
184 if (!m_found && strcmp(name, m_name) == 0)
187 *
reinterpret_cast<R *
>(m_pValue) = (m_pObject->*pm)();
193 GetValueHelperClass<T,BASE> &Assignable()
195#ifndef __INTEL_COMPILER
197 ((*
reinterpret_cast<std::string *
>(m_pValue) +=
"ThisObject:") +=
typeid(T).name()) +=
';';
198 if (!m_found && strncmp(m_name,
"ThisObject:", 11) == 0 && strcmp(m_name+11,
typeid(T).name()) == 0)
201 *
reinterpret_cast<T *
>(m_pValue) = *m_pObject;
211 const std::type_info *m_valueType;
213 bool m_found, m_getValueNames;
216template <
class BASE,
class T>
217GetValueHelperClass<T, BASE> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULLPTR)
219 return GetValueHelperClass<T, BASE>(pObject, name, valueType, pValue, searchFirst);
223GetValueHelperClass<T, T> GetValueHelper(
const T *pObject,
const char *name,
const std::type_info &valueType,
void *pValue,
const NameValuePairs *searchFirst=NULLPTR)
225 return GetValueHelperClass<T, T>(pObject, name, valueType, pValue, searchFirst);
230template <
class T,
class BASE>
231class AssignFromHelperClass
235 : m_pObject(pObject), m_source(source), m_done(false)
239 else if (
typeid(BASE) !=
typeid(T))
240 pObject->BASE::AssignFrom(source);
244 AssignFromHelperClass & operator()(
const char *name,
void (T::*pm)(
const R&))
249 if (!m_source.GetValue(name, value))
250 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name +
"'");
251 (m_pObject->*pm)(value);
256 template <
class R,
class S>
257 AssignFromHelperClass & operator()(
const char *name1,
const char *name2,
void (T::*pm)(
const R&,
const S&))
262 if (!m_source.GetValue(name1, value1))
263 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name1 +
"'");
265 if (!m_source.GetValue(name2, value2))
266 throw InvalidArgument(std::string(
typeid(T).name()) +
": Missing required parameter '" + name2 +
"'");
267 (m_pObject->*pm)(value1, value2);
278template <
class BASE,
class T>
279AssignFromHelperClass<T, BASE> AssignFromHelper(T *pObject,
const NameValuePairs &source)
281 return AssignFromHelperClass<T, BASE>(pObject, source);
285AssignFromHelperClass<T, T> AssignFromHelper(T *pObject,
const NameValuePairs &source)
287 return AssignFromHelperClass<T, T>(pObject, source);
294#ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER
297CRYPTOPP_DLL
bool AssignIntToInteger(
const std::type_info &valueType,
void *pInteger,
const void *pInt);
300CRYPTOPP_DLL
const std::type_info &
CRYPTOPP_API IntegerTypeId();
310 ParameterNotUsed(
const char *name) :
Exception(OTHER_ERROR, std::string(
"AlgorithmParametersBase: parameter \"") + name +
"\" not used") {}
316#if defined(CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS)
317 if (std::uncaught_exceptions() == 0)
318#elif defined(CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION)
319 if (std::uncaught_exception() ==
false)
324 if (m_throwIfNotUsed && !m_used)
327#if !defined(CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION)
328# if !defined(CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS)
338 : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used)
350 : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(false) {}
352 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
358 virtual void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
359 virtual void MoveInto(
void *p)
const =0;
362 bool m_throwIfNotUsed;
384 void AssignValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const
386#ifndef CRYPTOPP_NO_ASSIGN_TO_INTEGER
388 if (!(
typeid(T) ==
typeid(
int) && AssignIntToInteger(valueType, pValue, &m_value)))
392 *
reinterpret_cast<T *
>(pValue) = m_value;
396#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
397# pragma push_macro("new")
401 void MoveInto(
void *buffer)
const
407#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
408# pragma pop_macro("new")
452 , m_defaultThrowIfNotUsed(throwIfNotUsed)
469 p->m_next.reset(m_next.release());
470 m_next.reset(p.release());
471 m_defaultThrowIfNotUsed = throwIfNotUsed;
482 return operator()(name, value, m_defaultThrowIfNotUsed);
485 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const;
489 bool m_defaultThrowIfNotUsed;
514#define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name)
515#define CRYPTOPP_SET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Set##name)
516#define CRYPTOPP_SET_FUNCTION_ENTRY2(name1, name2) (Name::name1(), Name::name2(), &ThisClass::Set##name1##And##name2)
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Exception thrown when an AlgorithmParameter is unused.
Base class for AlgorithmParameters.
AlgorithmParametersBase(const char *name, bool throwIfNotUsed)
Construct a AlgorithmParametersBase.
An object that implements NameValuePairs.
AlgorithmParameters & operator()(const char *name, const T &value)
Appends a NameValuePair to a collection of NameValuePairs.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
AlgorithmParameters()
Construct a AlgorithmParameters.
AlgorithmParameters & operator()(const char *name, const T &value, bool throwIfNotUsed)
Template base class for AlgorithmParameters.
AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed)
Construct an AlgorithmParametersTemplate.
Used to pass byte array input as part of a NameValuePairs object.
byte * end() const
Pointer beyond the last byte in the memory block.
byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
ByteArrayParameter(SecByteBlock &block)
Construct a ByteArrayParameter.
ByteArrayParameter(byte *data=NULL, unsigned int size=0)
Construct a ByteArrayParameter.
Combines two sets of NameValuePairs.
CombinedNameValuePairs(const NameValuePairs &pairs1, const NameValuePairs &pairs2)
Construct a CombinedNameValuePairs.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Used to pass byte array input as part of a NameValuePairs object.
const byte * begin() const
Pointer to the first byte in the memory block.
ConstByteArrayParameter(const T &string, bool deepCopy=false)
Construct a ConstByteArrayParameter.
ConstByteArrayParameter(const byte *data, size_t size, bool deepCopy=false)
Construct a ConstByteArrayParameter.
const byte * end() const
Pointer beyond the last byte in the memory block.
size_t size() const
Length of the memory block.
ConstByteArrayParameter(const char *data=NULL, bool deepCopy=false)
Construct a ConstByteArrayParameter.
void Assign(const byte *data, size_t size, bool deepCopy)
Assign contents from a memory buffer.
Base class for all exceptions thrown by the library.
An invalid argument was detected.
Interface for retrieving values given their names.
virtual CRYPTOPP_DLL bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
static CRYPTOPP_DLL void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
Ensures an expected name and type is present.
Library configuration file.
#define CRYPTOPP_API
Win32 calling convention.
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
Abstract base classes that provide a uniform interface to this library.
Multiple precision integer with arithmetic operations.
Utility functions for the Crypto++ library.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes for automatic resource management.