Crypto++  5.6.5
Free C++ class library of cryptographic schemes
algparam.cpp
1 // algparam.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 
5 #ifndef CRYPTOPP_IMPORTS
6 
7 #include "algparam.h"
8 #include "integer.h"
9 
10 NAMESPACE_BEGIN(CryptoPP)
11 
12 PAssignIntToInteger g_pAssignIntToInteger = NULL;
13 
14 bool CombinedNameValuePairs::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
15 {
16  if (strcmp(name, "ValueNames") == 0)
17  return m_pairs1.GetVoidValue(name, valueType, pValue) && m_pairs2.GetVoidValue(name, valueType, pValue);
18  else
19  return m_pairs1.GetVoidValue(name, valueType, pValue) || m_pairs2.GetVoidValue(name, valueType, pValue);
20 }
21 
22 void AlgorithmParametersBase::operator=(const AlgorithmParametersBase &rhs)
23 {
24  CRYPTOPP_UNUSED(rhs);
25  CRYPTOPP_ASSERT(false);
26 }
27 
28 bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
29 {
30  if (strcmp(name, "ValueNames") == 0)
31  {
32  NameValuePairs::ThrowIfTypeMismatch(name, typeid(std::string), valueType);
33  if (m_next.get())
34  m_next->GetVoidValue(name, valueType, pValue);
35  (*reinterpret_cast<std::string *>(pValue) += m_name) += ";";
36  return true;
37  }
38  else if (strcmp(name, m_name) == 0)
39  {
40  AssignValue(name, valueType, pValue);
41  m_used = true;
42  return true;
43  }
44  else if (m_next.get())
45  return m_next->GetVoidValue(name, valueType, pValue);
46  else
47  return false;
48 }
49 
50 AlgorithmParameters::AlgorithmParameters()
51  : m_defaultThrowIfNotUsed(true)
52 {
53 }
54 
55 AlgorithmParameters::AlgorithmParameters(const AlgorithmParameters &x)
56  : m_defaultThrowIfNotUsed(x.m_defaultThrowIfNotUsed)
57 {
58  m_next.reset(const_cast<AlgorithmParameters &>(x).m_next.release());
59 }
60 
61 AlgorithmParameters & AlgorithmParameters::operator=(const AlgorithmParameters &x)
62 {
63  m_next.reset(const_cast<AlgorithmParameters &>(x).m_next.release());
64  return *this;
65 }
66 
67 bool AlgorithmParameters::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
68 {
69  if (m_next.get())
70  return m_next->GetVoidValue(name, valueType, pValue);
71  else
72  return false;
73 }
74 
75 NAMESPACE_END
76 
77 #endif
Classes for working with NameValuePairs.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: algparam.cpp:67
Base class for AlgorithmParameters.
Definition: algparam.h:311
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: algparam.cpp:14
STL namespace.
Combines two sets of NameValuePairs.
Definition: algparam.h:135
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:62
static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
Ensures an expected name and type is present.
Definition: cryptlib.h:394
An object that implements NameValuePairs.
Definition: algparam.h:435
Multiple precision integer with arithmetic operations.
Crypto++ library namespace.