Botan  1.11.17
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 70 of file scan_name.cpp.

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

Definition at line 74 of file scan_name.cpp.

References c, and deref_alias().

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

Definition at line 65 of file scan_name.cpp.

65  : SCAN_Name(algo_spec)
66  {
67  alg_name += extra;
68  }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:70

Member Function Documentation

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

Definition at line 201 of file scan_name.cpp.

202  {
203  std::lock_guard<std::mutex> lock(g_alias_map_mutex);
204 
205  if(g_alias_map.find(alias) == g_alias_map.end())
206  g_alias_map[alias] = basename;
207  }
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(), and Botan::OFB::make().

49 { return 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:139
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 139 of file scan_name.cpp.

References arg(), and arg_count().

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

References arg_count().

165  {
166  if(i >= arg_count())
167  return def_value;
168  return args[i];
169  }
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 171 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::make_block_cipher_mode_len(), and Botan::make_block_cipher_mode_len2().

172  {
173  if(i >= arg_count())
174  return def_value;
175  return to_u32bit(args[i]);
176  }
size_t arg_count() const
Definition: scan_name.h:64
u32bit to_u32bit(const std::string &str)
Definition: parsing.cpp:17
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().

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 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 (mode_info.size() >= 1) ? 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 (mode_info.size() >= 2) ? mode_info[1] : ""; }
std::string Botan::SCAN_Name::deref_alias ( const std::string &  alias)
static

Definition at line 209 of file scan_name.cpp.

Referenced by SCAN_Name().

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

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