Botan  1.11.26
Public Member Functions | Static Public Member Functions | List of all members
Botan::SCAN_Name Class Reference

#include <scan_name.h>

Public Member Functions

const std::string & algo_name () const
 
std::string algo_name_and_args () const
 
std::string all_arguments () 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)
 
 SCAN_Name (std::string algo_spec, const std::string &extra)
 

Static Public Member Functions

static void add_alias (const std::string &alias, const std::string &basename)
 
static std::string deref_alias (const std::string &alias)
 

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

Botan::SCAN_Name::SCAN_Name ( const char *  algo_spec)
Parameters
algo_specA SCAN-format name

Definition at line 69 of file scan_name.cpp.

69  : SCAN_Name(std::string(algo_spec))
70  {
71  }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:69
Botan::SCAN_Name::SCAN_Name ( std::string  algo_spec)
Parameters
algo_specA SCAN-format name

Definition at line 73 of file scan_name.cpp.

References deref_alias().

74  {
75  m_orig_algo_spec = algo_spec;
76 
77  std::vector<std::pair<size_t, std::string> > name;
78  size_t level = 0;
79  std::pair<size_t, std::string> accum = std::make_pair(level, "");
80 
81  const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
82 
83  algo_spec = SCAN_Name::deref_alias(algo_spec);
84 
85  for(size_t i = 0; i != algo_spec.size(); ++i)
86  {
87  char c = algo_spec[i];
88 
89  if(c == '/' || c == ',' || c == '(' || c == ')')
90  {
91  if(c == '(')
92  ++level;
93  else if(c == ')')
94  {
95  if(level == 0)
96  throw Decoding_Error(decoding_error + "Mismatched parens");
97  --level;
98  }
99 
100  if(c == '/' && level > 0)
101  accum.second.push_back(c);
102  else
103  {
104  if(accum.second != "")
105  name.push_back(deref_aliases(accum));
106  accum = std::make_pair(level, "");
107  }
108  }
109  else
110  accum.second.push_back(c);
111  }
112 
113  if(accum.second != "")
114  name.push_back(deref_aliases(accum));
115 
116  if(level != 0)
117  throw Decoding_Error(decoding_error + "Missing close paren");
118 
119  if(name.size() == 0)
120  throw Decoding_Error(decoding_error + "Empty name");
121 
122  m_alg_name = name[0].second;
123 
124  bool in_modes = false;
125 
126  for(size_t i = 1; i != name.size(); ++i)
127  {
128  if(name[i].first == 0)
129  {
130  m_mode_info.push_back(make_arg(name, i));
131  in_modes = true;
132  }
133  else if(name[i].first == 1 && !in_modes)
134  m_args.push_back(make_arg(name, i));
135  }
136  }
static std::string deref_alias(const std::string &alias)
Definition: scan_name.cpp:208
Botan::SCAN_Name::SCAN_Name ( std::string  algo_spec,
const std::string &  extra 
)
Parameters
algo_specA SCAN-format name

Definition at line 64 of file scan_name.cpp.

64  : SCAN_Name(algo_spec)
65  {
66  m_alg_name += extra;
67  }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:69

Member Function Documentation

void Botan::SCAN_Name::add_alias ( const std::string &  alias,
const std::string &  basename 
)
static

Definition at line 200 of file scan_name.cpp.

201  {
202  std::lock_guard<std::mutex> lock(g_alias_map_mutex);
203 
204  if(g_alias_map.find(alias) == g_alias_map.end())
205  g_alias_map[alias] = basename;
206  }
const std::string& Botan::SCAN_Name::algo_name ( ) const
inline
Returns
algorithm name

Definition at line 49 of file scan_name.h.

Referenced by Botan::get_eme(), Botan::get_kdf(), Botan::OAEP::make(), Botan::RC4::make(), Botan::CTR_BE::make(), Botan::OFB::make(), and Botan::PKCS8::PEM_encode().

49 { return m_alg_name; }
std::string Botan::SCAN_Name::algo_name_and_args ( ) const
inline
Returns
algorithm name plus any arguments

Definition at line 54 of file scan_name.h.

54 { return algo_name() + all_arguments(); }
std::string all_arguments() const
Definition: scan_name.cpp:138
const std::string & algo_name() const
Definition: scan_name.h:49
std::string Botan::SCAN_Name::all_arguments ( ) const
Returns
all arguments

Definition at line 138 of file scan_name.cpp.

References arg(), and arg_count().

139  {
140  std::string out;
141  if(arg_count())
142  {
143  out += "(";
144  for(size_t i = 0; i != arg_count(); ++i)
145  {
146  out += arg(i);
147  if(i != arg_count() - 1)
148  out += ",";
149  }
150  out += ")";
151  }
152  return out;
153  }
std::string arg(size_t i) const
Definition: scan_name.cpp:155
size_t arg_count() const
Definition: scan_name.h:64
std::string Botan::SCAN_Name::arg ( size_t  i) const
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 163 of file scan_name.cpp.

References arg_count().

164  {
165  if(i >= arg_count())
166  return def_value;
167  return m_args[i];
168  }
size_t arg_count() const
Definition: scan_name.h:64
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 170 of file scan_name.cpp.

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

Referenced by Botan::PSSR::make(), Botan::RC4::make(), Botan::Skein_512::make(), Botan::Blake2b::make(), Botan::Lion::make(), Botan::make_block_cipher_mode_len(), and Botan::make_block_cipher_mode_len2().

171  {
172  if(i >= arg_count())
173  return def_value;
174  return to_u32bit(m_args[i]);
175  }
size_t arg_count() const
Definition: scan_name.h:64
u32bit to_u32bit(const std::string &str)
Definition: parsing.cpp:18
size_t Botan::SCAN_Name::arg_count ( ) const
inline
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 71 of file scan_name.h.

Referenced by Botan::OAEP::make(), and Botan::Lion::make().

72  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
size_t arg_count() const
Definition: scan_name.h:64
const std::string& Botan::SCAN_Name::as_string ( ) const
inline
Returns
original input string

Definition at line 44 of file scan_name.h.

Referenced by arg().

44 { return m_orig_algo_spec; }
std::string Botan::SCAN_Name::cipher_mode ( ) const
inline
Returns
cipher mode (if any)

Definition at line 97 of file scan_name.h.

98  { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }
std::string Botan::SCAN_Name::cipher_mode_pad ( ) const
inline
Returns
cipher mode padding (if any)

Definition at line 103 of file scan_name.h.

104  { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }
std::string Botan::SCAN_Name::deref_alias ( const std::string &  alias)
static

Definition at line 208 of file scan_name.cpp.

Referenced by SCAN_Name().

209  {
210  std::lock_guard<std::mutex> lock(g_alias_map_mutex);
211 
212  std::string name = alias;
213 
214  for(auto i = g_alias_map.find(name); i != g_alias_map.end(); i = g_alias_map.find(name))
215  name = i->second;
216 
217  return name;
218  }

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