Botan  1.11.15
Public Member Functions | Static Public Member Functions
Botan::SCAN_Name Class Reference

#include <scan_name.h>

List of all members.

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.

                                          : SCAN_Name(std::string(algo_spec))
   {
   }
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().

   {
   orig_algo_spec = algo_spec;

   std::vector<std::pair<size_t, std::string> > name;
   size_t level = 0;
   std::pair<size_t, std::string> accum = std::make_pair(level, "");

   const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";

   algo_spec = SCAN_Name::deref_alias(algo_spec);

   for(size_t i = 0; i != algo_spec.size(); ++i)
      {
      char c = algo_spec[i];

      if(c == '/' || c == ',' || c == '(' || c == ')')
         {
         if(c == '(')
            ++level;
         else if(c == ')')
            {
            if(level == 0)
               throw Decoding_Error(decoding_error + "Mismatched parens");
            --level;
            }

         if(c == '/' && level > 0)
            accum.second.push_back(c);
         else
            {
            if(accum.second != "")
               name.push_back(deref_aliases(accum));
            accum = std::make_pair(level, "");
            }
         }
      else
         accum.second.push_back(c);
      }

   if(accum.second != "")
      name.push_back(deref_aliases(accum));

   if(level != 0)
      throw Decoding_Error(decoding_error + "Missing close paren");

   if(name.size() == 0)
      throw Decoding_Error(decoding_error + "Empty name");

   alg_name = name[0].second;

   bool in_modes = false;

   for(size_t i = 1; i != name.size(); ++i)
      {
      if(name[i].first == 0)
         {
         mode_info.push_back(make_arg(name, i));
         in_modes = true;
         }
      else if(name[i].first == 1 && !in_modes)
         args.push_back(make_arg(name, i));
      }
   }
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.

                                                                : SCAN_Name(algo_spec)
   {
   alg_name += extra;
   }

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.

   {
   std::lock_guard<std::mutex> lock(g_alias_map_mutex);

   if(g_alias_map.find(alias) == g_alias_map.end())
      g_alias_map[alias] = basename;
   }
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().

{ 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.

{ return algo_name() + all_arguments(); }
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().

   {
   std::string out;
   if(arg_count())
      {
      out += '(';
      for(size_t i = 0; i != arg_count(); ++i)
         {
         out += arg(i);
         if(i != arg_count() - 1)
            out += ',';
         }
      out += ')';
      }
   return out;
   }
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().

   {
   if(i >= arg_count())
      return def_value;
   return args[i];
   }
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().

   {
   if(i >= arg_count())
      return def_value;
   return to_u32bit(args[i]);
   }
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().

         { return ((arg_count() >= lower) && (arg_count() <= upper)); }
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().

{ 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.

         { 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.

         { 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().

   {
   std::lock_guard<std::mutex> lock(g_alias_map_mutex);

   std::string name = alias;

   for(auto i = g_alias_map.find(name); i != g_alias_map.end(); i = g_alias_map.find(name))
      name = i->second;

   return name;
   }

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