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

#include <scan_name.h>

Public Member Functions

std::string algo_name () const
 
std::string algo_name_and_args () 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
 
std::string as_string () const
 
std::string cipher_mode () const
 
std::string cipher_mode_pad () const
 
 SCAN_Name (std::string algo_spec)
 

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)
 
static void set_default_aliases ()
 

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 ( std::string  algo_spec)
Parameters
algo_specA SCAN-format name

Definition at line 68 of file scan_name.cpp.

References deref_alias().

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

Member Function Documentation

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

Definition at line 176 of file scan_name.cpp.

Referenced by set_default_aliases().

177  {
178  std::lock_guard<std::mutex> lock(s_alias_map_mutex);
179 
180  if(s_alias_map.find(alias) == s_alias_map.end())
181  s_alias_map[alias] = basename;
182  }
std::string Botan::SCAN_Name::algo_name ( ) const
inline
std::string Botan::SCAN_Name::algo_name_and_args ( ) const
Returns
algorithm name plus any arguments

Definition at line 133 of file scan_name.cpp.

References algo_name(), arg(), and arg_count().

Referenced by Botan::algorithm_kat_detailed().

134  {
135  std::string out;
136 
137  out = algo_name();
138 
139  if(arg_count())
140  {
141  out += '(';
142  for(size_t i = 0; i != arg_count(); ++i)
143  {
144  out += arg(i);
145  if(i != arg_count() - 1)
146  out += ',';
147  }
148  out += ')';
149 
150  }
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:49
std::string algo_name() const
Definition: scan_name.h:39
std::string Botan::SCAN_Name::arg ( size_t  i) const
Parameters
iwhich argument
Returns
ith argument

Definition at line 155 of file scan_name.cpp.

References arg_count().

Referenced by algo_name_and_args(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::find_hash(), Botan::Core_Engine::find_mac(), Botan::Core_Engine::find_pbkdf(), Botan::Core_Engine::find_stream_cipher(), Botan::get_eme(), Botan::get_emsa(), and Botan::get_kdf().

156  {
157  if(i >= arg_count())
158  throw std::range_error("SCAN_Name::argument - i out of range");
159  return args[i];
160  }
size_t arg_count() const
Definition: scan_name.h:49
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 162 of file scan_name.cpp.

References arg_count().

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

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

Referenced by Botan::OpenSSL_Engine::find_block_cipher(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::find_hash(), Botan::OpenSSL_Engine::find_stream_cipher(), Botan::Core_Engine::find_stream_cipher(), and Botan::get_emsa().

170  {
171  if(i >= arg_count())
172  return def_value;
173  return to_u32bit(args[i]);
174  }
size_t arg_count() const
Definition: scan_name.h:49
u32bit to_u32bit(const std::string &str)
Definition: parsing.cpp:16
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 56 of file scan_name.h.

Referenced by Botan::Core_Engine::find_block_cipher(), Botan::get_eme(), and Botan::get_emsa().

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

Definition at line 34 of file scan_name.h.

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

Definition at line 82 of file scan_name.h.

Referenced by Botan::algorithm_kat_detailed().

83  { 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 88 of file scan_name.h.

Referenced by Botan::algorithm_kat_detailed().

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

Definition at line 184 of file scan_name.cpp.

Referenced by SCAN_Name().

185  {
186  std::lock_guard<std::mutex> lock(s_alias_map_mutex);
187 
188  std::string name = alias;
189 
190  for(auto i = s_alias_map.find(name); i != s_alias_map.end(); i = s_alias_map.find(name))
191  name = i->second;
192 
193  return name;
194  }
void Botan::SCAN_Name::set_default_aliases ( )
static

Definition at line 196 of file scan_name.cpp.

References add_alias().

Referenced by Botan::Library_State::initialize().

197  {
198  // common variations worth supporting
199  SCAN_Name::add_alias("EME-PKCS1-v1_5", "PKCS1v15");
200  SCAN_Name::add_alias("3DES", "TripleDES");
201  SCAN_Name::add_alias("DES-EDE", "TripleDES");
202  SCAN_Name::add_alias("CAST5", "CAST-128");
203  SCAN_Name::add_alias("SHA1", "SHA-160");
204  SCAN_Name::add_alias("SHA-1", "SHA-160");
205  SCAN_Name::add_alias("MARK-4", "RC4(256)");
206  SCAN_Name::add_alias("ARC4", "RC4");
207  SCAN_Name::add_alias("OMAC", "CMAC");
208 
209  SCAN_Name::add_alias("EMSA-PSS", "PSSR");
210  SCAN_Name::add_alias("PSS-MGF1", "PSSR");
211  SCAN_Name::add_alias("EME-OAEP", "OAEP");
212 
213  SCAN_Name::add_alias("EMSA2", "EMSA_X931");
214  SCAN_Name::add_alias("EMSA3", "EMSA_PKCS1");
215  SCAN_Name::add_alias("EMSA-PKCS1-v1_5", "EMSA_PKCS1");
216 
217  // should be renamed in sources
218  SCAN_Name::add_alias("X9.31", "EMSA2");
219 
220  // kept for compatability with old library versions
221  SCAN_Name::add_alias("EMSA4", "PSSR");
222  SCAN_Name::add_alias("EME1", "OAEP");
223 
224  // probably can be removed
225  SCAN_Name::add_alias("GOST", "GOST-28147-89");
226  SCAN_Name::add_alias("GOST-34.11", "GOST-R-34.11-94");
227  }
static void add_alias(const std::string &alias, const std::string &basename)
Definition: scan_name.cpp:176

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