Botan  1.11.30
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)
explicit
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)
explicit
Parameters
algo_specA SCAN-format name

Definition at line 73 of file scan_name.cpp.

References deref_alias().

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

199  {
200  std::lock_guard<std::mutex> lock(g_alias_map_mutex);
201 
202  if(g_alias_map.find(alias) == g_alias_map.end())
203  g_alias_map[alias] = basename;
204  }
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:136
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 136 of file scan_name.cpp.

References arg(), and arg_count().

137  {
138  std::string out;
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  return out;
151  }
std::string arg(size_t i) const
Definition: scan_name.cpp:153
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 161 of file scan_name.cpp.

References arg_count().

162  {
163  if(i >= arg_count())
164  return def_value;
165  return m_args[i];
166  }
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 168 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().

169  {
170  if(i >= arg_count())
171  return def_value;
172  return to_u32bit(m_args[i]);
173  }
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 206 of file scan_name.cpp.

Referenced by SCAN_Name().

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

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