Botan  2.12.1
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::SCAN_Name Class Referencefinal

#include <scan_name.h>

Public Member Functions

const std::string & algo_name () const
 
std::string arg (size_t i) const
 
std::string arg (size_t i, const std::string &def_value) const
 
size_t arg_as_integer (size_t i, size_t def_value) const
 
size_t arg_count () const
 
bool arg_count_between (size_t lower, size_t upper) const
 
const std::string & as_string () const
 
std::string cipher_mode () const
 
std::string cipher_mode_pad () const
 
 SCAN_Name (const char *algo_spec)
 
 SCAN_Name (std::string algo_spec)
 
const std::string & to_string () const
 

Detailed Description

A class encapsulating a SCAN name (similar to JCE conventions) http://www.users.zetnet.co.uk/hopwood/crypto/scan/

Definition at line 23 of file scan_name.h.

Constructor & Destructor Documentation

◆ SCAN_Name() [1/2]

Botan::SCAN_Name::SCAN_Name ( const char *  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 56 of file scan_name.cpp.

56  : SCAN_Name(std::string(algo_spec))
57  {
58  }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:56

◆ SCAN_Name() [2/2]

Botan::SCAN_Name::SCAN_Name ( std::string  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 60 of file scan_name.cpp.

References name.

60  : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info()
61  {
62  if(algo_spec.size() == 0)
63  throw Invalid_Argument("Expected algorithm name, got empty string");
64 
65  std::vector<std::pair<size_t, std::string>> name;
66  size_t level = 0;
67  std::pair<size_t, std::string> accum = std::make_pair(level, "");
68 
69  const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
70 
71  for(size_t i = 0; i != algo_spec.size(); ++i)
72  {
73  char c = algo_spec[i];
74 
75  if(c == '/' || c == ',' || c == '(' || c == ')')
76  {
77  if(c == '(')
78  ++level;
79  else if(c == ')')
80  {
81  if(level == 0)
82  throw Decoding_Error(decoding_error + "Mismatched parens");
83  --level;
84  }
85 
86  if(c == '/' && level > 0)
87  accum.second.push_back(c);
88  else
89  {
90  if(accum.second != "")
91  name.push_back(accum);
92  accum = std::make_pair(level, "");
93  }
94  }
95  else
96  accum.second.push_back(c);
97  }
98 
99  if(accum.second != "")
100  name.push_back(accum);
101 
102  if(level != 0)
103  throw Decoding_Error(decoding_error + "Missing close paren");
104 
105  if(name.size() == 0)
106  throw Decoding_Error(decoding_error + "Empty name");
107 
108  m_alg_name = name[0].second;
109 
110  bool in_modes = false;
111 
112  for(size_t i = 1; i != name.size(); ++i)
113  {
114  if(name[i].first == 0)
115  {
116  m_mode_info.push_back(make_arg(name, i));
117  in_modes = true;
118  }
119  else if(name[i].first == 1 && !in_modes)
120  m_args.push_back(make_arg(name, i));
121  }
122  }
std::string name

Member Function Documentation

◆ algo_name()

const std::string& Botan::SCAN_Name::algo_name ( ) const
inline

◆ arg() [1/2]

std::string Botan::SCAN_Name::arg ( size_t  i) const
Parameters
iwhich argument
Returns
ith argument

Definition at line 124 of file scan_name.cpp.

References arg_count(), to_string(), and Botan::ASN1::to_string().

Referenced by Botan::HashFunction::create(), Botan::AEAD_Mode::create(), Botan::MessageAuthenticationCode::create(), Botan::BlockCipher::create(), Botan::KDF::create(), Botan::StreamCipher::create(), Botan::PBKDF::create(), Botan::Cipher_Mode::create(), Botan::PasswordHashFamily::create(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), Botan::get_eme(), Botan::get_emsa(), and Botan::hash_for_emsa().

125  {
126  if(i >= arg_count())
127  throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) +
128  " out of range for '" + to_string() + "'");
129  return m_args[i];
130  }
size_t arg_count() const
Definition: scan_name.h:56
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
const std::string & to_string() const
Definition: scan_name.h:41

◆ arg() [2/2]

std::string Botan::SCAN_Name::arg ( size_t  i,
const std::string &  def_value 
) const
Parameters
iwhich argument
def_valuethe default value
Returns
ith argument or the default value

Definition at line 132 of file scan_name.cpp.

References arg_count().

133  {
134  if(i >= arg_count())
135  return def_value;
136  return m_args[i];
137  }
size_t arg_count() const
Definition: scan_name.h:56

◆ arg_as_integer()

size_t Botan::SCAN_Name::arg_as_integer ( size_t  i,
size_t  def_value 
) const
Parameters
iwhich argument
def_valuethe default value
Returns
ith argument as an integer, or the default value

Definition at line 139 of file scan_name.cpp.

References arg_count(), and Botan::to_u32bit().

Referenced by Botan::HashFunction::create(), Botan::AEAD_Mode::create(), Botan::BlockCipher::create(), Botan::MessageAuthenticationCode::create(), Botan::StreamCipher::create(), Botan::Cipher_Mode::create(), and Botan::get_emsa().

140  {
141  if(i >= arg_count())
142  return def_value;
143  return to_u32bit(m_args[i]);
144  }
size_t arg_count() const
Definition: scan_name.h:56
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:35

◆ arg_count()

size_t Botan::SCAN_Name::arg_count ( ) const
inline

◆ arg_count_between()

bool Botan::SCAN_Name::arg_count_between ( size_t  lower,
size_t  upper 
) const
inline
Parameters
loweris the lower bound
upperis the upper bound
Returns
if the number of arguments is between lower and upper

Definition at line 63 of file scan_name.h.

Referenced by Botan::BlockCipher::create(), Botan::StreamCipher::create(), and Botan::get_emsa().

64  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
size_t arg_count() const
Definition: scan_name.h:56

◆ as_string()

const std::string& Botan::SCAN_Name::as_string ( ) const
inline

Definition at line 43 of file scan_name.h.

References Botan::ASN1::to_string().

44  {
45  return this->to_string();
46  }
const std::string & to_string() const
Definition: scan_name.h:41

◆ cipher_mode()

std::string Botan::SCAN_Name::cipher_mode ( ) const
inline
Returns
cipher mode (if any)

Definition at line 89 of file scan_name.h.

Referenced by Botan::commoncrypto_opts_from_algo().

90  { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }

◆ cipher_mode_pad()

std::string Botan::SCAN_Name::cipher_mode_pad ( ) const
inline
Returns
cipher mode padding (if any)

Definition at line 95 of file scan_name.h.

Referenced by Botan::commoncrypto_opts_from_algo().

96  { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }

◆ to_string()

const std::string& Botan::SCAN_Name::to_string ( ) const
inline
Returns
original input string

Definition at line 41 of file scan_name.h.

Referenced by arg().

41 { return m_orig_algo_spec; }

The documentation for this class was generated from the following files: