Botan  1.11.34
Crypto and TLS for C++11
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 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)
 

Detailed Description

A class encapsulating a SCAN name (similar to JCE conventions) http://www.users.zetnet.co.uk/hopwood/crypto/scan/

Definition at line 22 of file scan_name.h.

Constructor & Destructor Documentation

§ SCAN_Name() [1/2]

Botan::SCAN_Name::SCAN_Name ( const char *  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 57 of file scan_name.cpp.

57  : SCAN_Name(std::string(algo_spec))
58  {
59  }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:57

§ SCAN_Name() [2/2]

Botan::SCAN_Name::SCAN_Name ( std::string  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 61 of file scan_name.cpp.

61  : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info()
62  {
63  std::vector<std::pair<size_t, std::string> > name;
64  size_t level = 0;
65  std::pair<size_t, std::string> accum = std::make_pair(level, "");
66 
67  const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
68 
69  for(size_t i = 0; i != algo_spec.size(); ++i)
70  {
71  char c = algo_spec[i];
72 
73  if(c == '/' || c == ',' || c == '(' || c == ')')
74  {
75  if(c == '(')
76  ++level;
77  else if(c == ')')
78  {
79  if(level == 0)
80  throw Decoding_Error(decoding_error + "Mismatched parens");
81  --level;
82  }
83 
84  if(c == '/' && level > 0)
85  accum.second.push_back(c);
86  else
87  {
88  if(accum.second != "")
89  name.push_back(accum);
90  accum = std::make_pair(level, "");
91  }
92  }
93  else
94  accum.second.push_back(c);
95  }
96 
97  if(accum.second != "")
98  name.push_back(accum);
99 
100  if(level != 0)
101  throw Decoding_Error(decoding_error + "Missing close paren");
102 
103  if(name.size() == 0)
104  throw Decoding_Error(decoding_error + "Empty name");
105 
106  m_alg_name = name[0].second;
107 
108  bool in_modes = false;
109 
110  for(size_t i = 1; i != name.size(); ++i)
111  {
112  if(name[i].first == 0)
113  {
114  m_mode_info.push_back(make_arg(name, i));
115  in_modes = true;
116  }
117  else if(name[i].first == 1 && !in_modes)
118  m_args.push_back(make_arg(name, i));
119  }
120  }

Member Function Documentation

§ algo_name()

const std::string& Botan::SCAN_Name::algo_name ( ) const
inline

§ arg() [1/2]

std::string Botan::SCAN_Name::arg ( size_t  i) const
Parameters
iwhich argument
Returns
ith argument

Definition at line 122 of file scan_name.cpp.

References arg_count(), as_string(), and Botan::ASN1::to_string().

Referenced by Botan::MessageAuthenticationCode::create(), Botan::PBKDF::create(), Botan::StreamCipher::create(), Botan::KDF::create(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), Botan::get_aead(), Botan::get_cipher_mode(), Botan::get_eme(), Botan::get_emsa(), Botan::hash_for_emsa(), and Botan::PKCS8::PEM_encode().

123  {
124  if(i >= arg_count())
125  throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) +
126  " out of range for '" + as_string() + "'");
127  return m_args[i];
128  }
size_t arg_count() const
Definition: scan_name.h:50
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
const std::string & as_string() const
Definition: scan_name.h:40

§ arg() [2/2]

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 130 of file scan_name.cpp.

References arg_count().

131  {
132  if(i >= arg_count())
133  return def_value;
134  return m_args[i];
135  }
size_t arg_count() const
Definition: scan_name.h:50

§ arg_as_integer()

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 137 of file scan_name.cpp.

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

Referenced by Botan::MessageAuthenticationCode::create(), Botan::StreamCipher::create(), Botan::get_aead(), Botan::get_cipher_mode(), and Botan::get_emsa().

138  {
139  if(i >= arg_count())
140  return def_value;
141  return to_u32bit(m_args[i]);
142  }
size_t arg_count() const
Definition: scan_name.h:50
u32bit to_u32bit(const std::string &str)
Definition: parsing.cpp:18

§ arg_count()

size_t Botan::SCAN_Name::arg_count ( ) const
inline

§ arg_count_between()

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 57 of file scan_name.h.

Referenced by Botan::get_emsa().

58  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
size_t arg_count() const
Definition: scan_name.h:50

§ as_string()

const std::string& Botan::SCAN_Name::as_string ( ) const
inline
Returns
original input string

Definition at line 40 of file scan_name.h.

Referenced by arg().

40 { return m_orig_algo_spec; }

§ cipher_mode()

std::string Botan::SCAN_Name::cipher_mode ( ) const
inline
Returns
cipher mode (if any)

Definition at line 83 of file scan_name.h.

84  { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }

§ cipher_mode_pad()

std::string Botan::SCAN_Name::cipher_mode_pad ( ) const
inline
Returns
cipher mode padding (if any)

Definition at line 89 of file scan_name.h.

90  { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }

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